From 8d47febf4c4b96de44ea365722b76e744fa4676a Mon Sep 17 00:00:00 2001 From: Neil Gorski Date: Sun, 30 Mar 2025 23:09:59 +0200 Subject: [PATCH] pactice done --- 01/app.js | 8 ++++++++ 02/app.js | 7 ++++++- 03/app.js | 14 +++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/01/app.js b/01/app.js index 96dc2f5..7b22e58 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 (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..36b09ca 100644 --- a/02/app.js +++ b/02/app.js @@ -1,2 +1,7 @@ const x = 5; -let result = 0; \ No newline at end of file +let result = 0; + +for (i = 1; i <= x; i++) { + result += i; + console.log(`${i}. ${result} = ${result - i} + ${i} `); +} diff --git a/03/app.js b/03/app.js index c26c886..aa1cff1 100644 --- a/03/app.js +++ b/03/app.js @@ -1,3 +1,15 @@ const x = 10; let iteration = 0; -let randomNumber = -1; \ No newline at end of file +let randomNumber = -1; + +while (randomNumber != x) { + iteration++; + randomNumber = Math.round(Math.random() * 20); + if (randomNumber != x) { + console.log( + `${iteration}. iteration - random number was ${randomNumber}, but you try to hit ${x}` + ); + } else { + console.log(`On the ${iteration}. you hit x(${x})`); + } +}