-
Notifications
You must be signed in to change notification settings - Fork 205
Tasks Done #172
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 Done #172
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,28 @@ | ||
| const a = '4.2'; | ||
| const b = 9; | ||
|
|
||
| console.log(a, b); | ||
| console.log(a, b); | ||
|
|
||
| console.log("a:", typeof a); | ||
| console.log("b:", typeof b); | ||
|
|
||
| const operObj = { | ||
| sum: parseInt(b) + parseInt(a), | ||
| sub: parseInt(b) - parseInt(a), | ||
| divd: parseInt(b) / parseInt(a), | ||
| mult: parseInt(b) * parseInt(a), | ||
| concat: String(a) + parseInt(b), | ||
| modulo: parseInt(b) % parseInt(a) | ||
| }; | ||
|
|
||
| for (const key in operObj) { | ||
| if (operObj[key] > 20) { | ||
| console.log(`Wartość ${key} jest większa od 20`); | ||
| } else if (operObj[key] === 20) { | ||
| console.log(`Wartość ${key} jest równa 20`) | ||
| } else if (operObj[key] < 20) { | ||
| console.log(`Wartość ${key} jest mniejsza niż 20`) | ||
| } else if (typeof operObj[key] !== "number") { | ||
| console.log(`Wartość ${key} nie jest ${typeof operObj[key]}`) | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,21 @@ | ||
| <!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"> | ||
| <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,37 @@ | ||
|
|
||
| /* rozwiązanie z pętlą for */ | ||
| const x = 4; | ||
| const x = parseInt(prompt('Podaj liczbę!')); | ||
|
|
||
|
|
||
| for (let i = 1; i < 10; i++) { | ||
| const result = x * i; | ||
| console.log(`${x} * ${i} = ${result}`); | ||
| } | ||
|
|
||
| /* rozwiązanie z pętlą while */ | ||
| const a = parseInt(prompt('Wprowadź podstawę potęgi!')); | ||
| const n = parseInt(prompt('Wprowadź wykładnik potęgi!')); | ||
|
|
||
| if (isNaN(a) || isNaN(n)) { | ||
| console.error('Wprowadzono nieodpowiedni format danych. Odśwież stronę i spróbuj jeszcze raz!'); | ||
| } else { | ||
| let j = 2; | ||
| const powResult = Math.pow(a, n); | ||
|
|
||
| let message = `${a}` | ||
|
|
||
| if (n === 0) { | ||
| message = `${a} do potęgi zerowej to zero!`; | ||
| } else if (n === 1) { | ||
| message = `${a} do potęgi 1 to ${a}!`; | ||
| } else if (n === -1) { | ||
| message = `${a} do potęgi 1 to -${a}!`; | ||
| } else { | ||
| while (j <= n) { | ||
| const addon = ` * ${a}` | ||
| message = `${message}${addon}`; | ||
|
|
||
| /* rozwiązanie z pętlą while */ | ||
| j++ | ||
| }; | ||
| console.log(message + ' = ' + powResult); | ||
| }; | ||
| }; | ||
|
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,21 @@ | ||
| <!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"> | ||
| <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 |
|---|---|---|
|
|
@@ -8,11 +8,49 @@ const c = randomNumber(min, max); | |
| console.log(a, b, c); | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| const isEven = function (int) { | ||
| if (typeof int === 'number') { | ||
| if (int % 2 === 0) { | ||
| return true | ||
| } else { | ||
| return false | ||
| } | ||
| } else { | ||
| return null | ||
| } | ||
| }; | ||
|
|
||
| function randomNumber(min, max) { | ||
| return Math.round((Math.random() * (max - min)) + min); | ||
| } | ||
| }; | ||
|
|
||
| function getSum(a, b, c) { | ||
| const aP = parseInt(a); | ||
| const bP = parseInt(b); | ||
| const cP = parseInt(c); | ||
|
|
||
| const min = Math.min(aP, bP, cP); | ||
| return aP + bP + cP - min | ||
| }; | ||
|
|
||
| function showInfo(x, y) { | ||
| switch (y) { | ||
| 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 nie parzysty`); | ||
| break; | ||
| default: | ||
| console.error('Wprowadzono błędne parametry funkcji showInfo! Parametr "y" przyjmuje wartości: "null", "true" lub "false".') | ||
| }; | ||
| }; | ||
|
|
||
|
|
||
| const sum = getSum(a, b, c); | ||
| const sumIsEven = isEven(sum); | ||
|
|
||
| showInfo(sum, sumIsEven); | ||
|
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 |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| const array = createArray(10, 200); | ||
| const top10 = getLargest(array); | ||
| console.log(getAvg(top10)); | ||
|
|
||
|
|
||
|
|
||
|
|
||
| function createArray(min, max) { | ||
| const array = []; | ||
|
|
||
| for (let i = 0; i < 20; i++) { | ||
| const randomNumber = Math.round((Math.random() * (max - min)) + min); | ||
| array.push(randomNumber); | ||
| }; | ||
|
|
||
| return array | ||
| }; | ||
|
|
||
| function getLargest(array) { | ||
| const newArray = array.sort((a, b) => b - a).slice(0, 10); | ||
| return newArray | ||
| }; | ||
|
|
||
| function getAvg(array) { | ||
| const avg = array.reduce((inc, curr) => { | ||
| return inc += 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. Przydałoby się sprawdzić czy nie dzielimy przez 0 :) |
||
|
|
||
| return avg | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,21 @@ | ||
| <!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"> | ||
| <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 (className, grade) { | ||
| if (this.grades[className]) { | ||
| this.grades[className].push(grade) | ||
| } else ( | ||
| this.grades[className] = [grade] | ||
| ) | ||
| }; | ||
|
|
||
| Student.prototype.getAverageGrade = function (className) { | ||
|
|
||
| if (!className) { | ||
| let avg = 0; | ||
|
|
||
| for (const key in this.grades) { | ||
| const avgKey = this.grades[key].reduce((inc, curr) => { | ||
| return inc += curr | ||
| }, 0) / this.grades[key].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. Uważamy na dzielenie przez 0 :) Faktycznie mało prawdopodbne, że występuje nazwa przedmiotu bez oceny, ale może jutro czy za miesiąc zostanie dodana metoda o usuwaniu ocen przypadkowo wystawionych i już na pewno nie będziesz pamiętał, aby dodać tutaj warunek dzielenia przez 0 :) |
||
| avg += avgKey; | ||
|
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. Musimy pamiętać, że w programowaniu często liczby są przechowywane w systemie dwójkowym, co powoduje, że operacje na wartościach ułamkowych może prowadzić do niedokładności (najczęstszy przykład, wpisz do consoli 0.1+02 (patrz screen). Dlatego lepiej najpierw zsumować oceny i potem podzielić przez ich ilość, a nie robić średnią dla każdego
z osobna. |
||
| } | ||
|
|
||
| return avg / Object.keys(this.grades).length; | ||
| } else if (typeof className === "string") { | ||
| const avgSub = this.grades[className].reduce((inc, curr) => { | ||
| return inc += curr | ||
| }, 0) / this.grades[className].length; | ||
|
|
||
| return avgSub | ||
|
Comment on lines
+30
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. Zwróć uwagę, że ta część jest dość podobna do tej z linii 22-25, lepiej by było napisać funkcję, która przyjmuje przez paramtr tablicę z ocenami i liczy średnią. Potem ta funkcja w obu miejscach jest uruchamiana. |
||
| } else { | ||
| return console.error('Zły format parametru getAverageGrade()') | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,21 @@ | ||
| <!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"> | ||
| <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.
👍