-
Notifications
You must be signed in to change notification settings - Fork 206
practice-js-basics #157
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?
practice-js-basics #157
Conversation
devmentor-pl
left a comment
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.
Bartku,
Rozwiązanie są ok 👍
Znalazłem jednak parę błędów (postaraj się poprawić) i zostawiłem kilka sugestii :)
01/assets/js/app.js
Outdated
| const result1 = Number(a) + Number(b); | ||
| const result2 = Number(a) - Number(b); | ||
| const result3 = Number(a) * Number(b); | ||
| const result4 = Number(a) / Number(b); | ||
| const result5 = Number(a) % Number(b); | ||
|
|
||
| console.log( | ||
| result1 > 20 ? "Result1 is greater than 20" : "Result1 is less than 20" | ||
| ); | ||
| console.log( | ||
| result2 > 20 ? "Result2 is greater than 20" : "Result2 is less than 20" | ||
| ); | ||
| console.log( | ||
| result3 > 20 ? "Result3 is greater than 20" : "Result3 is less than 20" | ||
| ); | ||
| console.log( | ||
| result4 > 20 ? "Result4 is greater than 20" : "Result4 is less than 20" | ||
| ); | ||
| console.log( | ||
| result5 > 20 ? "Result5 is greater than 20" : "Result5 is less than 20" | ||
| ); |
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.
Jest zgodnie z treścią zadania, ale można by było to usprawnić. Wygodniej by było zapisywać wyniki do tablicy i potem wykorzystać pętlę do wyświetlania danych. Zdecydowanie zgrabniejsze rozwiązanie ;)
02/app.js
Outdated
| const x = 4; | ||
| const x = prompt("Type number: "); | ||
|
|
||
| if (x) { |
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.
Tu nie wystarczające sprawdzenie - wystarczy podać znak i już obliczanie nie działa.
02/app.js
Outdated
| while (!a) { | ||
| a = Number(prompt("Podstawa: ")); | ||
|
|
||
| while (!n || n <= 1) { | ||
| n = Number(prompt("Wykladnik:")); |
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.
Tutaj podobnie. Podajemy dowolny znak, a potem poprawny i już nie liczy :P
| const sum = getSum(a, b, c); | ||
| const even = isEven(sum); | ||
|
|
||
| showInfo(sum, even); |
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.
👍
04/app.js
Outdated
| @@ -0,0 +1,28 @@ | |||
| function createArray(min, max) { | |||
| if (typeof min !== "number" || typeof max !== "number") | |||
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.
Warto pamiętać, że NaN to też "number". Ale NaN === NaN => false - można to wykorzystać ;)
05/app.js
Outdated
| const calcAverage = (grades) => | ||
| grades.reduce((acc, cur) => acc + cur, 0) / grades.length; | ||
|
|
||
| if (typeof subject === "undefined") { | ||
| const grades = Object.values(this.grades).flat(); | ||
| return Number(calcAverage(grades).toFixed(2)); | ||
| } | ||
|
|
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.
Bardzo fajne rozwiązanie!
PS. Jeszcze sprawdziłbym czy grades nie jest pustą tablicą, bo inaczej dzielimy przez 0
devmentor-pl
left a comment
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.
Bartku,
Teraz jest super!
| console.log( | ||
| `${a} ${operation} ${b} is ${result > 20 ? "greater" : "less"} than 20` | ||
| ); | ||
| }); |
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.
👍
| } | ||
| counter++; | ||
| } | ||
|
|
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.
👍
|
|
||
| if (min > max) { | ||
| throw new Error("min must be less than or equal to max."); | ||
| } |
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.
👍
| const calcAverage = (grades) => { | ||
| if (!grades || grades.length === 0) throw new Error("No grades found!"); | ||
| return grades.reduce((acc, cur) => acc + cur, 0) / grades.length; | ||
| }; |
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.
👍
No description provided.