From ca8d96d3e895f5453cbeee080e37be5be56f6b24 Mon Sep 17 00:00:00 2001 From: Jaro Date: Mon, 26 Feb 2024 12:12:07 +0100 Subject: [PATCH 1/3] Finished ex 1 in loops --- 01/app.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/01/app.js b/01/app.js index 96dc2f5..fe53bd5 100644 --- a/01/app.js +++ b/01/app.js @@ -1,2 +1,10 @@ const randomNumber = Math.round(Math.random() * 20); console.log(randomNumber); + + +if (randomNumber > 5) { + for (let i=5; i<=randomNumber; i++) + console.log(i); +} else { + console.log('Wylosowana liczba jest zbyt mała, aby użyć pętli'); +} \ No newline at end of file From 629d3636fb200521b2df8f4f20a51f3e5a330818 Mon Sep 17 00:00:00 2001 From: Jaro Date: Mon, 26 Feb 2024 12:35:59 +0100 Subject: [PATCH 2/3] Finished ex 2 in loops --- 02/app.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/02/app.js b/02/app.js index 8a41914..bd97ae2 100644 --- a/02/app.js +++ b/02/app.js @@ -1,2 +1,18 @@ const x = 5; -let result = 0; \ No newline at end of file +let result = 0; + +// for (let i=1; i<=x; i++) { +// result = result + i; +// } +// console.log(result); + + +let i=1; + +while (i<=x) { + result = result + i; + i++ + +} + +console.log(result); \ No newline at end of file From b46df06dacaad8bf0da3f3fa3318c9c4b4d42543 Mon Sep 17 00:00:00 2001 From: Jaro Date: Mon, 26 Feb 2024 12:53:27 +0100 Subject: [PATCH 3/3] Finished ex 3 in loops --- 03/app.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/03/app.js b/03/app.js index c26c886..c7defe1 100644 --- a/03/app.js +++ b/03/app.js @@ -1,3 +1,10 @@ const x = 10; let iteration = 0; -let randomNumber = -1; \ No newline at end of file +let randomNumber = -1; + +while (randomNumber !== x) { + randomNumber = Math.round(Math.random() * 20) + iteration++ +} + +console.log(iteration, "tyle iteracji potrzeba do wylosowania", x); \ No newline at end of file