From 1d4200486c0bcb87395ba967d2c4140bd0737296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Ko=C5=82tuniak?= Date: Tue, 17 Feb 2026 19:45:01 +0100 Subject: [PATCH 1/6] add task 1 --- 01/assets/js/app.js | 26 +++++++++++++++++++++++++- 01/index.html | 5 ++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/01/assets/js/app.js b/01/assets/js/app.js index 9323b98d..9f669b3b 100644 --- a/01/assets/js/app.js +++ b/01/assets/js/app.js @@ -1,4 +1,28 @@ const a = '4.2'; const b = 9; -console.log(a, b); \ No newline at end of file +console.log(a, b); + +console.log(typeof a); +console.log(typeof b); + +const addition = Number(a) + b; +const concatenation = a + b.toString(); +const subtraction = a - b; +const multiplication = a * b; +const division = b / a; +const modulo = b % a; + +console.log( + `addition: ${addition}, concatenation: ${concatenation}, subtraction: ${subtraction}, multiplication: ${multiplication}, division: ${division}, modulo: ${modulo}`, +); + +const arr = [addition, concatenation, subtraction, multiplication, division, modulo]; + +arr.forEach(el => { + if (Number(el) >= 20) { + console.log(`${el} jest większe od 20`); + } else { + console.log(`${el} jest mniejsze od 20`); + } +}); diff --git a/01/index.html b/01/index.html index 5c55d687..ae1cffc9 100644 --- a/01/index.html +++ b/01/index.html @@ -1,12 +1,15 @@ + devmentor.pl - JS BASICS - #01 + - + + \ No newline at end of file From 48369e65e9edd7f2c192386c484b62f5e1d5d2d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Ko=C5=82tuniak?= Date: Wed, 18 Feb 2026 08:24:14 +0100 Subject: [PATCH 2/6] add task 2 --- 02/app.js | 40 +++++++++++++++++++++++++++++++++++++--- 02/index.html | 5 ++++- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/02/app.js b/02/app.js index b397190c..e0a7b9dd 100644 --- a/02/app.js +++ b/02/app.js @@ -1,7 +1,41 @@ - /* rozwiązanie z pętlą for */ -const x = 4; +// const x = 4; +const x = Number(prompt('Podaj liczbę!')); + +if (isNaN(x) || x < 1 || x > 9) { + console.log('Wpisz poprawną liczbę z zakresu 1-9.'); +} else { + for (let i = 1; i < 10; i++) { + console.log(`${x} x ${i} = ${x * i}`); + } +} + +/* rozwiązanie z pętlą while */ + +// const a = 3; +// const n = 4; + +const a = Number(prompt('Podaj podstawę potęgi 1-9')); +const n = Number(prompt('Podaj wykładnik potęgi 1-9')); + +if (isNaN(a) || isNaN(n) || a < 1 || a > 9 || n < 1 || n > 9) { + console.log('Wpisz poprawną liczbę z zakresu 1-9.'); +} else { + let i = 1; + let result = 1; + let text = ''; + + while (i <= n) { + result *= a; + if (i === n) { + text += `${a}`; + } else { + text += `${a} * `; + } + i++; + } -/* rozwiązanie z pętlą while */ \ No newline at end of file + console.log(`${text} = ${result}`); +} diff --git a/02/index.html b/02/index.html index 30150099..4ed272e1 100644 --- a/02/index.html +++ b/02/index.html @@ -1,12 +1,15 @@ + devmentor.pl - JS BASICS - #02 + - + + \ No newline at end of file From 58a1858d3c7647708f06dca8928691a879904e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Ko=C5=82tuniak?= Date: Wed, 18 Feb 2026 10:06:15 +0100 Subject: [PATCH 3/6] add task 3 --- 03/app.js | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/03/app.js b/03/app.js index 5b9361e4..dbe30c53 100644 --- a/03/app.js +++ b/03/app.js @@ -4,15 +4,47 @@ const max = 100; const a = randomNumber(min, max); const b = randomNumber(min, max); const c = randomNumber(min, max); +// const a = 21; +// const b = 33; +// const c = 21; console.log(a, b, c); - - - - - +function getSum(num1, num2, num3) { + const intNum1 = parseInt(num1); + const intNum2 = parseInt(num2); + const intNum3 = parseInt(num3); + + return [intNum1, intNum2, intNum3] + .sort((a, b) => a - b) + .slice(-2) + .reduce((acc, curr) => acc + curr, 0); +} + +const isEven = function (num) { + return typeof num !== 'number' ? null : num % 2 === 0; +}; + +const showInfo = (val, flag) => { + switch (flag) { + case null: + console.log(`Podany argument ${val} nie jest liczbą`); + break; + case true: + console.log(`Podany argument ${val} jest parzysty`); + break; + case false: + console.log(`Podany argument ${val} jest nieparzysty`); + break; + default: + console.log('Drugi parametr musi być: null, true lub false'); + } +}; function randomNumber(min, max) { - return Math.round((Math.random() * (max - min)) + min); -} \ No newline at end of file + return Math.round(Math.random() * (max - min) + min); +} + +const totalSum = getSum(a, b, c); +const isNumberIsEven = isEven(totalSum); +showInfo(totalSum, isNumberIsEven); From bd1dba71799b47069c065e3eb34b66319966dd3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Ko=C5=82tuniak?= Date: Wed, 18 Feb 2026 10:34:01 +0100 Subject: [PATCH 4/6] add task 4 --- 04/app.js | 28 ++++++++++++++++++++++++++++ 04/index.html | 5 ++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 04/app.js diff --git a/04/app.js b/04/app.js new file mode 100644 index 00000000..6b418a6f --- /dev/null +++ b/04/app.js @@ -0,0 +1,28 @@ +const min = 1; +const max = 100; + +const arr = createArray(1, 100); +console.log(arr); + +const largest = getLargest(arr); +console.log(largest); + +const avg = getAvg(largest); +console.log(avg); + +function createArray(min, max) { + const arr = []; + for (let i = 0; i < 20; i++) { + const num = Math.round(Math.random() * (max - min) + min); + arr.push(num); + } + return arr; +} + +function getLargest(array) { + return array.sort((a, b) => b - a).slice(0, 10); +} + +function getAvg(array) { + return array.reduce((acc, curr) => acc + curr, 0) / array.length; +} diff --git a/04/index.html b/04/index.html index 06aebbb8..65888d5a 100644 --- a/04/index.html +++ b/04/index.html @@ -1,12 +1,15 @@ + devmentor.pl - JS BASICS - #04 + - + + \ No newline at end of file From d2488aff33ee67421612fd1e2e6f52450a98c41b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Ko=C5=82tuniak?= Date: Wed, 18 Feb 2026 11:27:50 +0100 Subject: [PATCH 5/6] add task 5 --- 05/app.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 05/index.html | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 05/app.js diff --git a/05/app.js b/05/app.js new file mode 100644 index 00000000..6753d9e3 --- /dev/null +++ b/05/app.js @@ -0,0 +1,42 @@ +function Student(initFirstName, initLastName) { + this.firstName = initFirstName; + this.lastName = initLastName; + this.grades = {}; +} + +Student.prototype.addGrade = function (subject, grade) { + if (!this.grades[subject]) { + this.grades[subject] = []; + } + return this.grades[subject].push(grade); +}; + +Student.prototype.getAverageGrade = function (subject) { + if (!subject) { + const newArr = []; + for (const sub in this.grades) { + newArr.push(...this.grades[sub]); + } + return Number((newArr.reduce((acc, curr) => acc + curr, 0) / newArr.length).toFixed(2)); + } else { + if (!this.grades[subject]) { + return 'Nie ma takiego przedmiotu'; + } else { + return Number( + (this.grades[subject].reduce((acc, curr) => acc + curr, 0) / this.grades[subject].length).toFixed(2), + ); + } + } +}; + +const student = new Student('Jan', 'Kowalski'); +student.addGrade('maths', 4); +student.addGrade('maths', 6); +student.addGrade('english', 3); +console.log(student); +const avgMath = student.getAverageGrade('maths'); +const avgMath1 = student.getAverageGrade('math'); +console.log(avgMath); +console.log(avgMath1); +const avg = student.getAverageGrade(); +console.log(avg); diff --git a/05/index.html b/05/index.html index 52a42709..0dfb10b7 100644 --- a/05/index.html +++ b/05/index.html @@ -7,6 +7,6 @@ devmentor.pl - JS BASICS - #05 - + \ No newline at end of file From e1380eddc76997511eb64d0d07a111ab7405a677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Ko=C5=82tuniak?= Date: Sat, 21 Feb 2026 13:07:11 +0100 Subject: [PATCH 6/6] refactor: add calculateAverage method --- 05/app.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/05/app.js b/05/app.js index 6753d9e3..9c46ff4a 100644 --- a/05/app.js +++ b/05/app.js @@ -17,18 +17,20 @@ Student.prototype.getAverageGrade = function (subject) { for (const sub in this.grades) { newArr.push(...this.grades[sub]); } - return Number((newArr.reduce((acc, curr) => acc + curr, 0) / newArr.length).toFixed(2)); + return this.calculateAverage(newArr); } else { if (!this.grades[subject]) { return 'Nie ma takiego przedmiotu'; } else { - return Number( - (this.grades[subject].reduce((acc, curr) => acc + curr, 0) / this.grades[subject].length).toFixed(2), - ); + return this.calculateAverage(this.grades[subject]); } } }; +Student.prototype.calculateAverage = function (arr) { + return Number((arr.reduce((acc, curr) => acc + curr, 0) / arr.length).toFixed(2)); +}; + const student = new Student('Jan', 'Kowalski'); student.addGrade('maths', 4); student.addGrade('maths', 6);