From 0edfa13b16faff8be22683d8310d2d60cc85e505 Mon Sep 17 00:00:00 2001 From: Piotr Date: Thu, 31 Oct 2024 13:54:26 +0100 Subject: [PATCH] =?UTF-8?q?zadania=20utrwalak=C4=85ce=20p=C4=99tle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 01/app.js | 5 +++++ 02/app.js | 6 +++++- 03/app.js | 10 +++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/01/app.js b/01/app.js index 96dc2f5..722b080 100644 --- a/01/app.js +++ b/01/app.js @@ -1,2 +1,7 @@ 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 diff --git a/02/app.js b/02/app.js index 8a41914..cc31198 100644 --- a/02/app.js +++ b/02/app.js @@ -1,2 +1,6 @@ const x = 5; -let result = 0; \ No newline at end of file +let result = 0; +for (let i = 1; i <= x; i++) { + result += i; + console.log(result); +} \ No newline at end of file diff --git a/03/app.js b/03/app.js index c26c886..a126854 100644 --- a/03/app.js +++ b/03/app.js @@ -1,3 +1,11 @@ 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("Liczba wylosowana:", randomNumber); +console.log("Liczba iteracji:", iteration); \ No newline at end of file