From 5413e93bb8e25d0cc4c3cf7a7f935dcdb20d5849 Mon Sep 17 00:00:00 2001 From: Piotr Date: Tue, 12 Nov 2024 10:37:14 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Cz=C4=99=C5=9B=C4=87=20projektu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 01/assets/js/app.js | 58 ++++++++++++++++++++++++++++++++++++++++++++- 01/index.html | 2 +- 02/app.js | 24 ++++++++++++++++--- 3 files changed, 79 insertions(+), 5 deletions(-) diff --git a/01/assets/js/app.js b/01/assets/js/app.js index 9323b98d..9bb0029b 100644 --- a/01/assets/js/app.js +++ b/01/assets/js/app.js @@ -1,4 +1,60 @@ 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 sum = Number(a) + b; +const difference = Number(a) - b; +const multiplication = Number(a) * b; +const division = Number(a) / b; +const modulo = Number(a) % b; +const exponentiation = Math.pow(Number(a), b); + + +console.log("Suma: " + sum); +console.log("Różnica: " + difference); +console.log("Iloczyn: " + multiplication); +console.log("Iloraz: " + division); +console.log("Reszta: " + modulo); +console.log("Potęga: " + exponentiation); + +if (sum > 20) { + console.log('Suma jest większa niż 20'); +} else { + console.log('Suma jest mniejsza lub równa 20'); +} + +if (difference > 20) { + console.log('Różnica jest większa niż 20'); +} else { + console.log('Różnica jest mniejsza lub równa 20'); +} + +if (multiplication > 20) { + console.log('Iloczyn jest większy niż 20'); +} else { + console.log('Iloczyn jest mniejszy lub równy 20'); +} + +if (division > 20) { + console.log('Iloraz jest większy niż 20'); +} else { + console.log('Iloraz jest mniejszy lub równy 20'); +} + +if (modulo > 20) { + console.log('Reszta jest większa niż 20'); +} else { + console.log('Reszta jest mniejsza lub równa 20'); +} + +if (exponentiation > 20) { + console.log('Potęga jest większa niż 20'); +} else { + console.log('Potęga jest mniejsza lub równa 20'); +} \ No newline at end of file diff --git a/01/index.html b/01/index.html index 5c55d687..759d1238 100644 --- a/01/index.html +++ b/01/index.html @@ -7,6 +7,6 @@ devmentor.pl - JS BASICS - #01 - + \ No newline at end of file diff --git a/02/app.js b/02/app.js index b397190c..7380ffb0 100644 --- a/02/app.js +++ b/02/app.js @@ -1,7 +1,25 @@ +const x = prompt('Podaj liczbę'); -/* rozwiązanie z pętlą for */ -const x = 4; +if (x >= 1 && x <= 9) { + + for (let i = 1; i <= 9; i++) { + console.log(x + " x " + i + " = " + (x * i)); + } +} else { + console.log('Podana liczba jest poza zakresem! Proszę podać liczbę od 1 do 9.'); +} +/* rozwiązanie z pętlą while */ +let a = prompt("Podaj podstawę"); +let n = prompt("Podaj wykładnik"); -/* rozwiązanie z pętlą while */ \ No newline at end of file +let result = 1; + +let i = 0; + +while (i < n) { + result = result * a; +} + +console.log(a + " do potęgi " + n + " to " + result); \ No newline at end of file From a6eeafd51fecebe994fb2602325dd3d835736feb Mon Sep 17 00:00:00 2001 From: Piotr Date: Mon, 18 Nov 2024 13:18:42 +0100 Subject: [PATCH 2/2] zadania --- 02/app.js | 29 ++++++++++++++++++----------- 02/index.html | 2 +- 03/app.js | 42 +++++++++++++++++++++++++++++++++++++++--- 04/index.html | 2 +- 04/js/app.js | 41 +++++++++++++++++++++++++++++++++++++++++ 05/app.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 05/index.html | 2 +- 7 files changed, 146 insertions(+), 17 deletions(-) create mode 100644 04/js/app.js create mode 100644 05/app.js diff --git a/02/app.js b/02/app.js index 7380ffb0..53c101d3 100644 --- a/02/app.js +++ b/02/app.js @@ -1,13 +1,13 @@ -const x = prompt('Podaj liczbę'); +// const x = prompt('Podaj liczbę'); -if (x >= 1 && x <= 9) { +// if (x >= 1 && x <= 9) { - for (let i = 1; i <= 9; i++) { - console.log(x + " x " + i + " = " + (x * i)); - } -} else { - console.log('Podana liczba jest poza zakresem! Proszę podać liczbę od 1 do 9.'); -} +// for (let i = 1; i <= 9; i++) { +// console.log(x + " x " + i + " = " + (x * i)); +// } +// } else { +// console.log('Podana liczba jest poza zakresem! Proszę podać liczbę od 1 do 9.'); +// } /* rozwiązanie z pętlą while */ @@ -17,9 +17,16 @@ let n = prompt("Podaj wykładnik"); let result = 1; let i = 0; - +let str=''; while (i < n) { result = result * a; + i=i+1; + if (i===1) { + str=str+a + } + else { + str=str+'*'+a + } } - -console.log(a + " do potęgi " + n + " to " + result); \ No newline at end of file +console.log(str); +console.log(str+'='+result); \ 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 diff --git a/03/app.js b/03/app.js index 5b9361e4..28285da3 100644 --- a/03/app.js +++ b/03/app.js @@ -7,12 +7,48 @@ const c = randomNumber(min, max); console.log(a, b, c); - - +const result = getSum(a,b,c); +console.log(result); function randomNumber(min, max) { return Math.round((Math.random() * (max - min)) + min); -} \ No newline at end of file +} +function getSum(x,y,z) { + const intX=parseInt(x); + const intY=parseInt(y); + const intZ=parseInt(z); + const arr=[intX, intZ, intY]; + arr.sort(function(a,b){ + return a-b; + }) + console.log(arr) + return arr[1]+arr[2]; +} +const isEven = function(number) { + + if (typeof number !== 'number') { + return null; + } + + return number % 2 === 0; +}; +function showInfo(value, itResult) { + switch (itResult) { + + 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; + } +} +const itResult = isEven(result); + +showInfo(result, itResult); \ No newline at end of file diff --git a/04/index.html b/04/index.html index 06aebbb8..fd27a48a 100644 --- a/04/index.html +++ b/04/index.html @@ -7,6 +7,6 @@ devmentor.pl - JS BASICS - #04 - + \ No newline at end of file diff --git a/04/js/app.js b/04/js/app.js new file mode 100644 index 00000000..73cd4570 --- /dev/null +++ b/04/js/app.js @@ -0,0 +1,41 @@ + +function createArray(min, max) { + const array = []; + + for (let i = 0; i < 20; i++) { + const randNumber = Math.round((Math.random() * (max - min)) + min) + array.push(Math.round(randNumber)); + } + return array; + +} +const arr = createArray(1, 100); +console.log(arr) + +function getLargest (numbers) { + numbers.sort(function (a,b) { + return b-a; + + }) + const largest = numbers.slice(0,10); + return largest; +} +const largest = getLargest(arr); +console.log(largest); + +function getAvg(arr) { + const sum = arr.reduce(function (accumulator, currentValue) { + return accumulator + currentValue; + }, 0); + return sum / arr.length; + } + + const average = getAvg(arr); + console.log(average); + +const arr2 = createArray(10, 200); +console.log(arr2); +const largest2 = getLargest(arr2); +console.log(largest2); +const average2 = getAvg(arr2); +console.log(average2); \ No newline at end of file diff --git a/05/app.js b/05/app.js new file mode 100644 index 00000000..d00c4d4b --- /dev/null +++ b/05/app.js @@ -0,0 +1,45 @@ +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]; + const sum = grades.reduce(function (acc, grade) { + return acc + grade; + }, 0); + + return sum / grades.length; + } + + const allGrades = Object.values(this.grades).reduce(function (acc, grades) { + return acc.concat(grades); + }, []); + + const totalSum = allGrades.reduce(function (acc, grade) { + return acc + grade; + }, 0); + return totalSum / allGrades.length; +}; + + +//Przykład użycia +const student = new Student('Jan', 'Kowalski'); +student.addGrade('maths', 1); +student.addGrade('maths', 5); +student.addGrade('english', 4); + +const avgMath = student.getAverageGrade('maths'); +const avg = student.getAverageGrade(); + +console.log(avgMath); +console.log(avg); \ No newline at end of file diff --git a/05/index.html b/05/index.html index 52a42709..ea47e80b 100644 --- a/05/index.html +++ b/05/index.html @@ -7,6 +7,6 @@ devmentor.pl - JS BASICS - #05 - + \ No newline at end of file