From d88827a709367bbf8537b6588590dbc5e4f17cd7 Mon Sep 17 00:00:00 2001 From: PatrickStojek Date: Sun, 5 May 2024 16:52:10 +0200 Subject: [PATCH 1/4] first exercise complete --- 01/app.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/01/app.js b/01/app.js index 96dc2f5..0da3e97 100644 --- a/01/app.js +++ b/01/app.js @@ -1,2 +1,12 @@ const randomNumber = Math.round(Math.random() * 20); console.log(randomNumber); + +/// Anwer for the exercise + +if(randomNumber > 5){ + let i = 5 + while(i <= randomNumber) { + console.log(i) + i++ + } +} else alert("Wylosowana liczba jest zbyt mała, aby użyć pętli") \ No newline at end of file From 388fe7dd1fbb9f1b33682de79bd4f09418e44a26 Mon Sep 17 00:00:00 2001 From: PatrickStojek Date: Sun, 5 May 2024 16:59:58 +0200 Subject: [PATCH 2/4] exercise 2 completed --- 02/app.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/02/app.js b/02/app.js index 8a41914..5cec3cd 100644 --- a/02/app.js +++ b/02/app.js @@ -1,2 +1,9 @@ const x = 5; -let result = 0; \ No newline at end of file +let result = 0; + +for(let i = 0; i <= x; i++) { + result = result + i + console.log(result) +} + +console.log(result) \ No newline at end of file From 2e35da9ab389f4fea640547101f1bb71024f7350 Mon Sep 17 00:00:00 2001 From: PatrickStojek Date: Sun, 5 May 2024 17:03:51 +0200 Subject: [PATCH 3/4] add the same code using while loop --- 02/app.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/02/app.js b/02/app.js index 5cec3cd..72e6b67 100644 --- a/02/app.js +++ b/02/app.js @@ -6,4 +6,13 @@ for(let i = 0; i <= x; i++) { console.log(result) } -console.log(result) \ No newline at end of file +console.log(result) + +///here the same code but using while loop +let i = 0 +while(i <= x) { + result = result + i + console.log(result) + i++ +} +console.log(`The final result is ${result}`) \ No newline at end of file From dfda127d6379a59e0e66e9e44880ab9d8e40f368 Mon Sep 17 00:00:00 2001 From: PatrickStojek Date: Sun, 5 May 2024 17:17:44 +0200 Subject: [PATCH 4/4] exercise 3 completed --- 03/app.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/03/app.js b/03/app.js index c26c886..2a5da80 100644 --- a/03/app.js +++ b/03/app.js @@ -1,3 +1,12 @@ const x = 10; let iteration = 0; -let randomNumber = -1; \ No newline at end of file +let randomNumber = -1; + + +///Rozwiązanie zadania +while(randomNumber !== x) { + randomNumber = Math.floor(Math.random() * 21) + iteration++ +} + +console.log(iteration) \ No newline at end of file