diff --git a/01/app.js b/01/app.js index 96dc2f5..a89dc4c 100644 --- a/01/app.js +++ b/01/app.js @@ -1,2 +1,11 @@ -const randomNumber = Math.round(Math.random() * 20); -console.log(randomNumber); +for (let j = 0; j < 5; j++) { + const randomNumber = Math.round(Math.random() * 20) + + 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") + } +} diff --git a/02/app.js b/02/app.js index 8a41914..181258f 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 += i; + result = result + i +} +console.log(result) + +const x1 = 5 +let result1 = 0 +let j = 1 + +while (j <= x1) { + result1 += j + j++ +} +console.log(result1) \ No newline at end of file diff --git a/03/app.js b/03/app.js index c26c886..565fa2b 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 +const x = 5 +let iteration = 0 +let randomNumber + +while (randomNumber !== x) { + randomNumber = Math.floor(Math.random() * 10) + 1 + iteration++ +} + +console.log("Liczba iteracji: " + iteration)