From 989811b72f244636ab7f4861bc2f915e8d4f2042 Mon Sep 17 00:00:00 2001 From: Sebastian Pietrzykowski Date: Tue, 9 Apr 2024 12:58:56 +0200 Subject: [PATCH 1/3] add loop "for" --- 01/app.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/01/app.js b/01/app.js index 96dc2f5..5cf0738 100644 --- a/01/app.js +++ b/01/app.js @@ -1,2 +1,9 @@ const randomNumber = Math.round(Math.random() * 20); console.log(randomNumber); + +for (let i = 5; i < randomNumber; i++) { + console.log(i); +} +if (randomNumber < 5) { + console.log('Wylosowana liczba jest zbyt mała, aby użyć pętli'); +} From b85b7f1898e488ccb0b9a0891b23969880513365 Mon Sep 17 00:00:00 2001 From: Sebastian Pietrzykowski Date: Sun, 14 Apr 2024 11:42:49 +0200 Subject: [PATCH 2/3] loops exercises --- 02/app.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/02/app.js b/02/app.js index 8a41914..02e0985 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++) { + if(x < result) { + x = x + result + } + console.log(result); +} From ca476872e1b4bc0579c8e43de77099e38156c399 Mon Sep 17 00:00:00 2001 From: Sebastian Pietrzykowski Date: Sun, 12 May 2024 11:51:53 +0200 Subject: [PATCH 3/3] exercises no 1 and 2 - done --- 01/app.js | 4 ++-- 02/app.js | 21 ++++++++++++++------- 03/app.js | 15 ++++++++++++--- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/01/app.js b/01/app.js index 5cf0738..164dc25 100644 --- a/01/app.js +++ b/01/app.js @@ -1,9 +1,9 @@ const randomNumber = Math.round(Math.random() * 20); console.log(randomNumber); -for (let i = 5; i < randomNumber; i++) { +for (let i = 5; i <= randomNumber; i++) { console.log(i); } if (randomNumber < 5) { - console.log('Wylosowana liczba jest zbyt mała, aby użyć pętli'); + console.log("wlosowana liczba jest za mala"); } diff --git a/02/app.js b/02/app.js index 02e0985..ead076b 100644 --- a/02/app.js +++ b/02/app.js @@ -1,9 +1,16 @@ -const x = 5; -let result = 0; +const x = 5 +let result = 0 -for (let i = 0; i < x; i++) { - if(x < result) { - x = x + result - } - console.log(result); +for (let i = 1; i <= x; i++) { + // console.log(i); + + result = result + i } +console.log(`result = ${result}`); + + +while (result <= x) { + result = result + x + i++ +} +console.log(`result = ${result}`); \ No newline at end of file diff --git a/03/app.js b/03/app.js index c26c886..4a5e7ee 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 + +const x = 5 +let iteration = 0 + +while (iteration <= x) { + + iteration = iteration + x + iteration++ + console.log(iteration); + +} +console.log(iteration); \ No newline at end of file