From 3d6c1fd5f80948b09642cbefbf8c4056d907bbce Mon Sep 17 00:00:00 2001 From: PatrickStojek Date: Fri, 23 Aug 2024 21:22:29 +0200 Subject: [PATCH 1/5] task 1 completed --- 01/assets/js/app.js | 59 ++++++++++++++++++++++++++++++++++++++++++++- 01/index.html | 1 + 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/01/assets/js/app.js b/01/assets/js/app.js index 9323b98d..c10320e8 100644 --- a/01/assets/js/app.js +++ b/01/assets/js/app.js @@ -1,4 +1,61 @@ 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)) + +////operations +const addition = a + b +const subraction = a - b +const multiplication = a * b +const exponentiation = a**b +const division = a / b + +function checkAddition(addition) { + const result = Boolean(addition === parseFloat(a) + parseFloat(b)) + if(result) { + return addition + } else return parseFloat(a) + parseFloat(b) +} + +function checkSubtraction(subtraction) { + const result = Boolean(subtraction === parseFloat(a) - parseFloat(b)) + if(result) { + return subtraction + } else return parseFloat(a) - parseFloat(b) +} +function checkMultiplication(multiplication) { + const result = Boolean(multiplication === parseFloat(a) * parseFloat(b)) + if(result) { + return multiplication + } else return parseFloat(a) * parseFloat(b) +} +function checkDivision(division) { + const result = Boolean(division === parseFloat(a) / parseFloat(b)) + if(result) { + return division + } else return parseFloat(a) / parseFloat(b) +} +function checkExponation(exponentiation) { + const result = Boolean(exponentiation === parseFloat(a) ** parseFloat(b)) + if(result) { + return exponentiation + } else return parseFloat(a) ** parseFloat(b) +} + +function isBiggerthan20(result) { + if(result > 20) { + console.log('the result is bigger than 20') + } else console.log('the result is smaller than 20') +} + +const allResults = [addition, subraction, multiplication, exponentiation, division] +allResults.forEach(function(result) { + isBiggerthan20(result) +}) + + + + + diff --git a/01/index.html b/01/index.html index 5c55d687..383b56a2 100644 --- a/01/index.html +++ b/01/index.html @@ -4,6 +4,7 @@ + devmentor.pl - JS BASICS - #01 From bdbc4056bf09aa5481e6bc60a15bc10b3e5d8b01 Mon Sep 17 00:00:00 2001 From: PatrickStojek Date: Fri, 23 Aug 2024 23:24:07 +0200 Subject: [PATCH 2/5] task 2 completed --- 02/app.js | 31 +++++++++++++++++++++++++++++-- 02/index.html | 1 + 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/02/app.js b/02/app.js index b397190c..11df45cb 100644 --- a/02/app.js +++ b/02/app.js @@ -1,7 +1,34 @@ /* rozwiązanie z pętlą for */ -const x = 4; +const x = prompt("Podaj liczbę!") +for(let i = 1; i < 10; i++) { + console.log(x + '*' + i + '=' + x * i) +} +/* rozwiązanie z pętlą while */ -/* rozwiązanie z pętlą while */ \ No newline at end of file +function exponentiation() { + const a = parseFloat(prompt('podaj podstawę potęgi!')) + const n = parseFloat(prompt('podaj wykładnik potęgi!')) + + if(isNaN(a) || isNaN(n)) { + console.log('wrong input format') + return; + } + let counter = 1 + let output = '' + while(counter <= n) { + if(counter == 1) { + output += a + } else if(counter > 1 && counter !== n){ + output += '*' + a + } else { + output += '*' + a + '=' + a**n + } + counter++ + } + console.log(output) +} + +exponentiation() \ No newline at end of file diff --git a/02/index.html b/02/index.html index 30150099..387d91c6 100644 --- a/02/index.html +++ b/02/index.html @@ -4,6 +4,7 @@ + devmentor.pl - JS BASICS - #02 From 3be69ffe84a7a53cc3237e4ea780fa0aa7d1ddf9 Mon Sep 17 00:00:00 2001 From: PatrickStojek Date: Sat, 24 Aug 2024 00:44:15 +0200 Subject: [PATCH 3/5] task 3 completed --- 03/app.js | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/03/app.js b/03/app.js index 5b9361e4..31a29899 100644 --- a/03/app.js +++ b/03/app.js @@ -7,10 +7,43 @@ const c = randomNumber(min, max); console.log(a, b, c); - - - - +function getSum(num1, num2, num3) { + num1Int = parseInt(num1) + num2Int = parseInt(num2) + num3Int = parseInt(num3) + + const numbers = [num1Int, num2Int, num3Int] + numbers.sort((a,b) => b - a) + const sum = numbers[0] + numbers[1] + return sum +} + +const isEven = (num) => { + if(isNaN(num)){ + return null + } else { + if(num % 2 === 0) { + return true + } else return false + } +} + +function showInfo(sum,value) { + switch(value) { + case null: + console.log(`Podany argument ${sum} nie jest liczbą`) + break + case true: + console.log(`Podany argument ${sum} jest parzysty`) + break + case false: + console.log(`Podany argument ${sum} jest nieparzysty`) + } +} + +const sum = getSum(a,b, c) +const even = isEven(sum) +showInfo(sum, even) function randomNumber(min, max) { From 15410b9d9785461929568e0ab8d120c8755ac1b5 Mon Sep 17 00:00:00 2001 From: PatrickStojek Date: Sat, 24 Aug 2024 01:04:56 +0200 Subject: [PATCH 4/5] task 4 completed --- 04/app.js | 23 +++++++++++++++++++++++ 04/index.html | 1 + 2 files changed, 24 insertions(+) create mode 100644 04/app.js diff --git a/04/app.js b/04/app.js new file mode 100644 index 00000000..c8778579 --- /dev/null +++ b/04/app.js @@ -0,0 +1,23 @@ +function createArray(min, max) { + const array = [] + for(let i = 0; i < 20; i++) { + const number = Math.round(Math.random() * (max - min) + min) + array.push(number) + } + return array +} + +function sortArray(array) { + array.sort((a,b) => b - a) + return array.slice(0,10) +} + +function arithmeticAvarage(array){ + const arrayLength = array.length + const sum = array.reduce((acc, curr) => acc + curr) + const avarage = sum / arrayLength + return avarage +} + +const RandomArray = createArray(10,200) +console.log(arithmeticAvarage(sortArray(RandomArray))) diff --git a/04/index.html b/04/index.html index 06aebbb8..6a75dc77 100644 --- a/04/index.html +++ b/04/index.html @@ -4,6 +4,7 @@ + devmentor.pl - JS BASICS - #04 From 4cc94a6a49f4dd113b65f26bb678df7536813b92 Mon Sep 17 00:00:00 2001 From: PatrickStojek Date: Sat, 24 Aug 2024 02:13:35 +0200 Subject: [PATCH 5/5] task 5 completed --- 05/app.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 05/index.html | 1 + 2 files changed, 44 insertions(+) create mode 100644 05/app.js diff --git a/05/app.js b/05/app.js new file mode 100644 index 00000000..c3ab837e --- /dev/null +++ b/05/app.js @@ -0,0 +1,43 @@ +function Student(initFirstName, initLastName) { + this.firstName = initFirstName + thislastName = initLastName + this.grades = {} +} + +Student.prototype.addGrade = function(subject, grade) { + if(typeof this.grades[subject] === 'undefined') { + this.grades[subject] = [] + } + this.grades[subject].push(grade) +} + +Student.prototype.getAvarageGrade = function(subject) { + if(subject !== undefined) { + const gradesNumber = this.grades[subject].length + const sum = this.grades[subject].reduce((acc, curr) => acc + curr) + const avarage = sum / gradesNumber + return avarage + } else { + let totalGrades = 0; + let totalSum = 0; + for(subj in this.grades) { + const grades = this.grades[subj].length + const sum = this.grades[subj].reduce((acc, curr) => acc + curr) + totalSum += sum; + totalGrades += grades + } + const overallAvarage = totalSum / totalGrades; + return overallAvarage; + } +} + + +const Student1 = new Student("Ala", "Sobota") +Student1.addGrade('math', 5) +Student1.addGrade('math', 5) +Student1.addGrade('math', 4) +Student1.addGrade('english', 4) +Student1.addGrade('biology', 3) +console.log(Student1.getAvarageGrade()) +console.log(Student1) + diff --git a/05/index.html b/05/index.html index 52a42709..3da4921e 100644 --- a/05/index.html +++ b/05/index.html @@ -4,6 +4,7 @@ + devmentor.pl - JS BASICS - #05