-
Notifications
You must be signed in to change notification settings - Fork 205
add tasks 1-5 #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
add tasks 1-5 #174
Changes from all commits
1d42004
48369e6
58a1858
bd1dba7
d2488af
e1380ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,28 @@ | ||
| const a = '4.2'; | ||
| const b = 9; | ||
|
|
||
| console.log(a, b); | ||
| 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`); | ||
| } | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,15 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="pl"> | ||
|
|
||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
| <title>devmentor.pl - JS BASICS - #01</title> | ||
| </head> | ||
|
|
||
| <body> | ||
|
|
||
| <script src="./assets/js/app.js"></script> | ||
| </body> | ||
|
|
||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 */ | ||
| console.log(`${text} = ${result}`); | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,15 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="pl"> | ||
|
|
||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
| <title>devmentor.pl - JS BASICS - #02</title> | ||
| </head> | ||
|
|
||
| <body> | ||
|
|
||
| <script src="./app.js"></script> | ||
| </body> | ||
|
|
||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Super! |
||
| } | ||
|
|
||
| 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); | ||
| } | ||
| return Math.round(Math.random() * (max - min) + min); | ||
| } | ||
|
|
||
| const totalSum = getSum(a, b, c); | ||
| const isNumberIsEven = isEven(totalSum); | ||
| showInfo(totalSum, isNumberIsEven); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,15 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="pl"> | ||
|
|
||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
| <title>devmentor.pl - JS BASICS - #04</title> | ||
| </head> | ||
|
|
||
| <body> | ||
|
|
||
| <script src="./app.js"></script> | ||
| </body> | ||
|
|
||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| 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 this.calculateAverage(newArr); | ||
| } else { | ||
| if (!this.grades[subject]) { | ||
| return 'Nie ma takiego przedmiotu'; | ||
| } else { | ||
| return this.calculateAverage(this.grades[subject]); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| Student.prototype.calculateAverage = function (arr) { | ||
| return Number((arr.reduce((acc, curr) => acc + curr, 0) / arr.length).toFixed(2)); | ||
| }; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Zdecydowanie lepiej! Teraz jak będzie trzeba obliczać inaczej średnią - np. podawać 3 miejsca po przecinku to nie będzie to żaden problem. Najważniejsze, że taka zmiana będzie dotyczyć tylko jednego miejsca i zawsze staramy się do tego dążyć. |
||
|
|
||
| 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); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,6 @@ | |
| <title>devmentor.pl - JS BASICS - #05</title> | ||
| </head> | ||
| <body> | ||
|
|
||
| <script src="./app.js"></script> | ||
| </body> | ||
| </html> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍