-
Notifications
You must be signed in to change notification settings - Fork 205
Tasks completed #171
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?
Tasks completed #171
Changes from all commits
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,54 @@ | ||
| const a = '4.2'; | ||
| const b = 9; | ||
|
|
||
| console.log(a, b); | ||
| console.log(a, b); | ||
|
|
||
| console.log(typeof a, typeof b); | ||
|
|
||
| let addition = parseFloat(a) + b; | ||
| let substraction = a - b; | ||
| let multiplication = a * b; | ||
| let division = a / b; | ||
| let modulo = a % b; | ||
| let increment = a; | ||
| increment++; | ||
| let decrement = a; | ||
| decrement--; | ||
|
|
||
| console.log( | ||
| addition, | ||
| substraction, | ||
| multiplication, | ||
| division, | ||
| modulo, | ||
| increment, | ||
| decrement | ||
| ); | ||
|
|
||
| if (addition > 20) { | ||
| console.log('Addition result is grtater than 20'); | ||
| } | ||
|
|
||
| if (substraction > 20) { | ||
| console.log('Substraction result is grtater than 20'); | ||
| } | ||
|
|
||
| if (multiplication > 20) { | ||
| console.log('Multiplication result is grtater than 20'); | ||
| } | ||
|
|
||
| if (division > 20) { | ||
| console.log('Division result is grtater than 20'); | ||
| } | ||
|
|
||
| if (modulo > 20) { | ||
| console.log('Modulo result is grtater than 20'); | ||
| } | ||
|
|
||
| if (increment > 20) { | ||
| console.log('Incrementation result is grtater than 20'); | ||
| } | ||
|
|
||
| if (decrement > 20) { | ||
| console.log('Decrementation result is grtater than 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,40 @@ | ||
|
|
||
| /* rozwiązanie z pętlą for */ | ||
| const x = 4; | ||
| const x = parseInt(prompt('Podaj liczbę do mnożenia (od 1 do 9)')); | ||
|
|
||
| if (x > 0 && x <= 9) { | ||
| for (let i = 1; i <= 9; i++) { | ||
| console.log(`${x} x ${i} = ${x * i}`); | ||
| } | ||
| } else { | ||
| alert('Podana liczba nie jest z zakresu od 1 do 9'); | ||
| } | ||
|
|
||
| /* rozwiązanie z pętlą while */ | ||
|
|
||
| const a = parseInt(prompt('Podaj podstawę potęgi')); | ||
| const n = parseInt(prompt('Podaj wykładnik potęgi')); | ||
|
|
||
| let i = 1; | ||
| let result = a; | ||
| let resultMethod = a; | ||
|
|
||
| if (n === 0) { | ||
| result = 1; | ||
| } else if (n < 0) { | ||
| i = -1; | ||
| while (i > n) { | ||
| result *= a; | ||
| resultMethod = resultMethod + ' x ' + a; | ||
| i--; | ||
| } | ||
| resultMethod = '1 / (' + resultMethod + ')'; | ||
| result = 1 / result; | ||
| } else { | ||
| while (i < n) { | ||
| result *= a; | ||
| resultMethod = resultMethod + ' x ' + a; | ||
| i++; | ||
| } | ||
| } | ||
|
|
||
| /* rozwiązanie z pętlą while */ | ||
| console.log(resultMethod + ' = ' + 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,16 @@ | ||
| <!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 |
|---|---|---|
|
|
@@ -7,12 +7,47 @@ const c = randomNumber(min, max); | |
|
|
||
| console.log(a, b, c); | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| const isEven = function (num) { | ||
| if (typeof num !== 'number') { | ||
| return null; | ||
| } else { | ||
| return num % 2 === 0; | ||
| } | ||
| }; | ||
|
|
||
| const sum = getSum(a, b, c); | ||
| const even = isEven(sum); | ||
|
|
||
| showInfo(sum, even); | ||
|
|
||
| function getSum(a, b, c) { | ||
| a = parseInt(a); | ||
| b = parseInt(b); | ||
| c = parseInt(c); | ||
|
|
||
| if (a <= b && a <= c) { | ||
| return b + c; | ||
| } else if (b < a && b <= c) { | ||
| return a + c; | ||
| } else { | ||
| return a + b; | ||
| } | ||
|
Comment on lines
+28
to
+34
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. Tutaj również można wykorzystać tablicę - posortować i wybrać dwie pierwsze/ostatnie ;) |
||
| } | ||
|
|
||
| function showInfo(x, bool) { | ||
| switch (bool) { | ||
| case null: | ||
| console.log(`Podany argument ${x} nie jest liczbą`); | ||
| break; | ||
| case true: | ||
| console.log(`Podany argument ${x} jest parzysty`); | ||
| break; | ||
| case false: | ||
| console.log(`Podany argument ${x} jest nieparzysty`); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| function randomNumber(min, max) { | ||
| return Math.round((Math.random() * (max - min)) + min); | ||
| } | ||
| return Math.round(Math.random() * (max - min) + min); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| const min = 10; | ||
| const max = 200; | ||
|
|
||
| const arr = createArray(min, max); | ||
| const largest = getLargest(arr); | ||
| const avg = getAvg(largest); | ||
|
|
||
| console.log('Array: ' + arr); | ||
| console.log('10 Largest numbers: ' + largest); | ||
| console.log('Average value: ' + avg); | ||
|
|
||
| function getAvg(arr) { | ||
| return arr.reduce((a, b) => a + b) / arr.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. Warto pamiętać o drugim parametrze tj. |
||
| } | ||
|
|
||
| function getLargest(arr) { | ||
| return arr.sort((a, b) => b - a).slice(0, 10); | ||
| } | ||
|
|
||
| function createArray(min, max) { | ||
| const arr = []; | ||
| let number; | ||
| for (let i = 0; i < 20; i++) { | ||
| number = Math.round(Math.random() * (max - min)) + min; | ||
| arr.push(number); | ||
| } | ||
| return arr; | ||
| } | ||
| 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,38 @@ | ||
| 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 = null) { | ||
| let gradesArr; | ||
| if (subject !== null) { | ||
| gradesArr = this.grades[subject]; | ||
| } else { | ||
| gradesArr = Object.values(this.grades).flat(); | ||
| } | ||
|
|
||
| return ( | ||
| gradesArr.reduce((acc, curr) => acc + curr, 0) / gradesArr.length | ||
| ).toFixed(2); | ||
| }; | ||
|
|
||
| const artur = new Student('Artur', 'Testowy'); | ||
|
|
||
| artur.addGrade('maths', 5); | ||
| artur.addGrade('maths', 5); | ||
| artur.addGrade('maths', 4); | ||
| artur.addGrade('maths', 4); | ||
| artur.addGrade('physics', 4); | ||
| artur.addGrade('physics', 3); | ||
| artur.addGrade('physics', 5); | ||
|
|
||
| console.log(artur.getAverageGrade('maths')); | ||
| console.log(artur.getAverageGrade()); | ||
|
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 - #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.
Można było dodać wyniki działań do tablicy i wykorzystać pętlę do porównywania - byłoby ładnie ;P