From 3cdf261a7dfb79554f06c8de2eb18d0faa3905a5 Mon Sep 17 00:00:00 2001 From: Oleksii Krylov Date: Wed, 10 Sep 2025 13:07:17 +0200 Subject: [PATCH 1/5] 01 Done --- 01/assets/js/app.js | 42 +++++++++++++++++++++++++++++++++++++++++- 01/index.html | 2 +- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/01/assets/js/app.js b/01/assets/js/app.js index 9323b98d..efe9ad73 100644 --- a/01/assets/js/app.js +++ b/01/assets/js/app.js @@ -1,4 +1,44 @@ const a = '4.2'; const b = 9; -console.log(a, b); \ No newline at end of file +const y = parseFloat(a); + +console.log('a = ' + typeof(a)); +console.log('b = ' + typeof(b)); +console.log('y = ' + typeof(y)); + +console.log(a, b); + +const res1 = b + y; +const res2 = a - b; +const res3 = a * b; +const res4 = a / b; +const res5 = b % y; +let res6 = 1; res6++; +let res7 = 2; res7--; +const res8 = a + b; + +console.log('konkatenacja: ' + res8); +console.log('Dodawanie: ' + res1); +console.log('Odejmowanie: ' + res2); +console.log('Mnożenie: ' + res3); +console.log('Dzielenie: ' + res4); +console.log('Reszta z dzielenia: ' + res5); +console.log('Inkrementacja: ' + res6); +console.log('Dekrementacja: ' + res7); + + +function checkResult(name, value) { + if (value > 20) { + console.log(name + value + ' jest większy od 20'); + } else { + console.log(name + value + ' jest mniejszy od 20'); + } + +} + +checkResult('Dodawanie', res1); +checkResult('Odejmowanie', res2); +checkResult('Mnożenie ', res3); +checkResult('Dzielenie', res4); +checkResult('Reszta z dzielenia', res5); \ No newline at end of file diff --git a/01/index.html b/01/index.html index 5c55d687..c723b964 100644 --- a/01/index.html +++ b/01/index.html @@ -7,6 +7,6 @@ devmentor.pl - JS BASICS - #01 - + \ No newline at end of file From da7498a532cce6a1cf354058eb67d15f6cc1cd80 Mon Sep 17 00:00:00 2001 From: Oleksii Krylov Date: Wed, 10 Sep 2025 13:44:54 +0200 Subject: [PATCH 2/5] 02 Done --- 02/app.js | 30 ++++++++++++++++++++++++++++-- 02/index.html | 2 +- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/02/app.js b/02/app.js index b397190c..a1960f5e 100644 --- a/02/app.js +++ b/02/app.js @@ -1,7 +1,33 @@ /* rozwiązanie z pętlą for */ -const x = 4; +const x = prompt('Podaj numer'); +for(i=1; i<10; i++){ + console.log(x + 'x' + i + '=' + i * x); +} + +/* rozwiązanie z pętlą while */ + +const a = parseInt(prompt('Podaj podstawe')); +const n = parseInt(prompt('Podaj wykładnik')); + + +if(isNaN(a) || isNaN(n) || n < 0 ){ + console.log('podaj poprawne liczby'); +}else { + let result = 1; + let expression = ""; + let j = 0; + + while (j < n) { + result *= a; + expression += a; + if (j < n - 1) { + expression += " * "; + } + j++; + } + console.log(expression + " = " + result); +} -/* rozwiązanie z pętlą while */ \ No newline at end of file diff --git a/02/index.html b/02/index.html index 30150099..f597ba8e 100644 --- a/02/index.html +++ b/02/index.html @@ -7,6 +7,6 @@ devmentor.pl - JS BASICS - #02 - + \ No newline at end of file From 03643174a5a2e41665e8b276d3d906454ff4f93e Mon Sep 17 00:00:00 2001 From: Oleksii Krylov Date: Thu, 11 Sep 2025 10:39:45 +0200 Subject: [PATCH 3/5] 03 Done --- 03/app.js | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/03/app.js b/03/app.js index 5b9361e4..ff0a2025 100644 --- a/03/app.js +++ b/03/app.js @@ -5,10 +5,46 @@ const a = randomNumber(min, max); const b = randomNumber(min, max); const c = randomNumber(min, max); -console.log(a, b, c); - - - +const result = getSum(a, b, c); +const even = isEven(result); + +showInfo(result, even) + + + +function getSum(a, b, c){ + a = parseInt(a); + b = parseInt(b); + c = parseInt(c); + + const sorted = [a, b, c].sort((x, y) => y - x); + + return sorted[0] + sorted[1]; +} + +function isEven(num) { + if (typeof num !== "number") { + return null; + } + return num % 2 === 0; +} + + +function showInfo(value, flag) { + switch (flag) { + case null: + console.log(`Podany argument ${value} nie jest liczbą`); + break; + case true: + console.log(`Podany argument ${value} jest parzysty`); + break; + case false: + console.log(`Podany argument ${value} jest nieparzysty`); + break; + default: + console.log("Nieprawidłowa wartość drugiego parametru"); + } +} From f1447b9bd1375cf2ae12a1c0222c54dfd5b9bc48 Mon Sep 17 00:00:00 2001 From: Oleksii Krylov Date: Thu, 11 Sep 2025 10:54:18 +0200 Subject: [PATCH 4/5] 04 Done --- 04/app.js | 33 +++++++++++++++++++++++++++++++++ 04/index.html | 2 +- 2 files changed, 34 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..484087d0 --- /dev/null +++ b/04/app.js @@ -0,0 +1,33 @@ + + + +function createArray(min, max) { + const arr = []; + for (let i = 0; i < 20; i++) { + const random = Math.floor(Math.random() * (max - min + 1)) + min; + arr.push(random); + } + return arr; +} + + +function getLargest(arr) { + return arr + .sort((a, b) => b - a) + .slice(0, 10) +} + +function getAvg(arr) { + const sum = arr.reduce((acc, num) => acc + num, 0); + return sum / arr.length; +} + + +const arr = createArray(10, 200); +console.log( 'Tabela ', arr); + +const largest = getLargest(arr); +console.log(largest); + +const avg = getAvg(largest); +console.log("Średnia arytmetyczna ", avg); \ No newline at end of file diff --git a/04/index.html b/04/index.html index 06aebbb8..57557f85 100644 --- a/04/index.html +++ b/04/index.html @@ -7,6 +7,6 @@ devmentor.pl - JS BASICS - #04 - + \ No newline at end of file From 0b6a0c4d8313b3699ad65f82bc0f1addd4545259 Mon Sep 17 00:00:00 2001 From: Oleksii Krylov Date: Thu, 11 Sep 2025 11:15:09 +0200 Subject: [PATCH 5/5] 05 Done --- 05/app.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 05/index.html | 2 +- 2 files changed, 52 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..a21d7050 --- /dev/null +++ b/05/app.js @@ -0,0 +1,51 @@ +function Student(firstName, lastName) { + this.firstName = firstName; + this.lastName = lastName; + this.grades = {}; +} + + +Student.prototype.addGrade = function(subject, grade) { + if (typeof this.grades[subject] === 'undefined') { + this.grades[subject] = []; + } + this.grades[subject].push(grade); +}; + + +Student.prototype.getAverageGrade = function(subject) { + if (typeof subject !== 'undefined') { + + const grades = this.grades[subject]; + if (!grades || grades.length === 0) return 0; + + const sum = grades.reduce((acc, g) => acc + g, 0); + return (sum / grades.length).toFixed(2); + } else { + + let allGrades = []; + for (const key in this.grades) { + allGrades = allGrades.concat(this.grades[key]); + } + if (allGrades.length === 0) return 0; + + const sum = allGrades.reduce((acc, g) => acc + g, 0); + return (sum / allGrades.length).toFixed(2); + } +}; + +Student.prototype.getFullName = function() { + return `${this.firstName} ${this.lastName}`; +}; + + +const student = new Student('Jan', 'Kowalski'); + +student.addGrade('maths', 4); +student.addGrade('maths', 6); +student.addGrade('english', 3); + + +console.log(student.getFullName()); +console.log(student.getAverageGrade('maths')); +console.log(student.getAverageGrade()); diff --git a/05/index.html b/05/index.html index 52a42709..e2add3ff 100644 --- a/05/index.html +++ b/05/index.html @@ -7,6 +7,6 @@ devmentor.pl - JS BASICS - #05 - + \ No newline at end of file