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 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 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) { 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 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