From bfa7cee2c06b9e093e1f1673f117b667742afbb9 Mon Sep 17 00:00:00 2001 From: TetraMeister Date: Sat, 10 Jan 2026 22:53:34 +0100 Subject: [PATCH] Tasks done --- 01/app.js | 9 +++++++++ 02/app.js | 24 +++++++++++++++++++++++- 03/app.js | 15 +++++++++++++-- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/01/app.js b/01/app.js index 96dc2f5..1ccd1ba 100644 --- a/01/app.js +++ b/01/app.js @@ -1,2 +1,11 @@ const randomNumber = Math.round(Math.random() * 20); console.log(randomNumber); + + +if (randomNumber >= 5) { + for (let j = 5; j <= randomNumber; j++) { + console.log(j); + } +} 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..a066028 100644 --- a/02/app.js +++ b/02/app.js @@ -1,2 +1,24 @@ const x = 5; -let result = 0; \ No newline at end of file + +function forSum() { + let result = 0; + + for (let i = 0; i <= x; i++) { + result += i; + } + + return result +}; + +function whileSum() { + let result = 0; + let i = 0; + + while (i <= x) { + result += i; + + i++ + } + + return result +}; \ No newline at end of file diff --git a/03/app.js b/03/app.js index c26c886..abe97a2 100644 --- a/03/app.js +++ b/03/app.js @@ -1,3 +1,14 @@ const x = 10; -let iteration = 0; -let randomNumber = -1; \ No newline at end of file + +function guessNumber() { + let iteration = 0; + let randomNumber = Math.round(Math.random() * 20); + + while (randomNumber !== x) { + randomNumber = Math.round(Math.random() * 20); + console.log(`WYLOSOWANO: ${randomNumber}`) + iteration += 1; + } + + console.log(`Liczba iteracji losowań to: ${iteration}`); +} \ No newline at end of file