-
Notifications
You must be signed in to change notification settings - Fork 205
Complete all tasks #168
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?
Complete all tasks #168
Changes from all commits
6462b97
8e68e15
f1a47f0
bb59c26
b257968
e707d59
d4878b6
c56889b
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,75 @@ | ||
| const a = '4.2'; | ||
| const b = 9; | ||
|
|
||
| console.log(a, b); | ||
| console.log(a, b); | ||
| console.log("Constant a is of type:", typeof(a), ". Constant b is of type:", typeof(b)); | ||
|
|
||
| function sum(a, b) { | ||
| return Number(a) + b; | ||
| } | ||
|
|
||
| function difference(a, b) { | ||
| return Number(a) - b; | ||
| } | ||
|
|
||
| function product(a, b) { | ||
| return Number(a) * b; | ||
| } | ||
|
|
||
| function quotient(a, b) { | ||
| return Number(a) / b; | ||
| } | ||
|
|
||
| function remainder(a, b) { | ||
| return Number(a) % b; | ||
| } | ||
|
|
||
| function increment(a, b) { | ||
| let numA = Number(a); | ||
| numA++; | ||
| let numB = b; | ||
| numB++; | ||
| return [numA, numB]; | ||
| } | ||
|
|
||
| function decrement(a, b) { | ||
| let numA = Number(a); | ||
| numA--; | ||
| let numB = b; | ||
| numB--; | ||
| return [numA, numB]; | ||
| } | ||
|
|
||
| const addition = sum(a, b); | ||
| const subtraction = difference(a, b); | ||
| const multipliplication = product(a, b); | ||
| const division = quotient(a, b); | ||
| const modulo = remainder(a, b); | ||
| const postIncrement = increment(a, b); | ||
| const postDecrement = decrement(a, b); | ||
|
|
||
| console.log("Score of addition:", addition); | ||
| console.log("Score of subtraction:", subtraction); | ||
| console.log("Score of multipliplication:", multipliplication.toFixed(2)); | ||
| console.log("Score of division:", division.toFixed(2)); | ||
| console.log("Score of modulo:", modulo); | ||
| console.log("Scores od increment:", postIncrement); | ||
| console.log("Scores of decrement:", postDecrement); | ||
|
|
||
| const results = [ | ||
| { name: "Addition", value: addition}, | ||
| { name: "Substraction", value: subtraction}, | ||
| { name: "Multipliplication", value: multipliplication}, | ||
| { name: "Division", value: division}, | ||
| { name: "Modulo", value: modulo}, | ||
| { name: "postIncrement", value: postIncrement}, | ||
| { name: "postDecrement", value: postDecrement}, | ||
| ]; | ||
|
|
||
| for (const result of results) { | ||
| if (result.value > 20) { | ||
| console.log(`${result.name} is greater than 20`); | ||
| } else { | ||
| console.log(`${result.name} is less than or equal to 20`) | ||
| } | ||
| } | ||
| 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 = Number(prompt('Podaj liczbę od 1 do 9!')); | ||
|
|
||
| if(x > 9) { | ||
| alert("Za duża liczba, uczymy się do 9!"); | ||
| } else { | ||
| for(let i = 1; i <= 9; i++) { | ||
| const results = x * i; | ||
| console.log(`${x} x ${i} = ${results}`); | ||
| } | ||
| } | ||
|
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. 👍 |
||
|
|
||
|
|
||
| /* rozwiązanie z pętlą while */ | ||
|
|
||
| /* rozwiązanie z pętlą while */ | ||
|
|
||
| const a = Number(prompt('Podaj podstawę potęgowania! (max liczba 10)')); | ||
| const n = Number(prompt('Podaj wykładnij potęgowania! (max liczba 5)')); | ||
|
|
||
| let result = 1; | ||
| let sequence = ''; | ||
|
|
||
|
|
||
| if(a < 1 || a > 10 && n < 1 || n > 5) { | ||
| alert('Prosze podac prawidłowe liczby!'); | ||
| } else { | ||
| let i = 1; | ||
| while(i <= n) { | ||
| result *= a; | ||
| sequence += a; | ||
| if( i < n) sequence += ' * '; | ||
| i++; | ||
| } | ||
| console.log(`${sequence} = ${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 |
|---|---|---|
|
|
@@ -7,6 +7,6 @@ | |
| <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,10 +7,44 @@ const c = randomNumber(min, max); | |
|
|
||
| console.log(a, b, c); | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| function getSum(a, b, c) { | ||
| const numbers = [a, b, c]; | ||
| numbers.sort(function(a, b){ return b-a;}); | ||
| console.log("Sort numbers:", numbers); | ||
| const sum = numbers[0] + numbers[1]; | ||
| return sum; | ||
| } | ||
| const sum = getSum(a, b, c); | ||
| console.log("Sum of two greater numbers:", sum); | ||
|
|
||
| function isEven(num) { | ||
| if(typeof(num) === Number) { | ||
| return null; | ||
| } else { | ||
| if (num % 2 === 0 ) { | ||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| const isSumEven = isEven(sum); | ||
| console.log("Sum is even?", isSumEven); | ||
|
|
||
|
|
||
| function showInfo(sum, isSumEven) { | ||
| switch(isSumEven) { | ||
| 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 completeInfo = showInfo(sum, isSumEven); | ||
|
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. 👍 |
||
|
|
||
|
|
||
| function randomNumber(min, max) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
|
|
||
| function randomNumber(min, max) { | ||
| return Math.round((Math.random() * (max - min)) + min); | ||
| } | ||
|
|
||
| const arr = []; | ||
|
|
||
| for(let i = 0; i < 20; i++) { | ||
| arr.push(randomNumber(1, 200)); | ||
| } | ||
| console.log("Full array random 20 numbers:", arr); | ||
|
|
||
|
|
||
| function sortNumbers(arr) { | ||
| return arr.sort(function(a, b){return b-a}).slice(0, 9); | ||
| } | ||
| const largestNumbers = sortNumbers(arr); | ||
| console.log("Largest numbers:", largestNumbers); | ||
|
|
||
|
|
||
|
|
||
| function arithmeticMean(arr) { | ||
| if( arr.length === 0) { | ||
| return 0; | ||
| } | ||
| return arr.reduce((acc, curr) => acc + curr, 0) / arr.length; | ||
| } | ||
| console.log(`Arithmetic mean of ${arr} is ${arithmeticMean(arr)}`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,6 @@ | |
| <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,41 @@ | ||
| function Student(initFirstName, initLastName, initGrades) { | ||
| this.firstName = initFirstName; | ||
| this.lastName = initLastName; | ||
| this.grades = {}; | ||
| } | ||
|
|
||
| Student.prototype.addGrade = function(subject, grade) { | ||
| if (typeof this.grades[subject] === 'undefined') { | ||
| this.grades[subject] = []; | ||
| } | ||
| this.grades[subject].push(grade); | ||
| }; | ||
|
|
||
| const student = new Student('Sandra', 'Mstowska'); | ||
| student.addGrade('maths', 4); | ||
| student.addGrade('maths', 5); | ||
| student.addGrade('english', 3); | ||
| student.addGrade('english', 5); | ||
|
|
||
| Student.prototype.calculateAverage = function(grades) { | ||
| if (!grades || grades.length === 0) return 0; | ||
| const sum = grades.reduce((acc, val) => acc + val, 0); | ||
| return sum /grades.length; | ||
| }; | ||
|
|
||
|
|
||
| Student.prototype.getAverageGrade = function(subject) { | ||
| if (subject) { | ||
| return this.calculateAverage(this.grades[subject]); | ||
|
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! Zobacz jak bardzo zwiększyła się czytelność! |
||
| } else { | ||
| const allGrades = Object.values(this.grades).flat(); | ||
| return this.calculateAverage(allGrades); | ||
| } | ||
| }; | ||
|
|
||
| student.addGrade('polish', 1); | ||
|
|
||
| console.log(student); | ||
| console.log("Średnia wszytskich ocen:", student.getAverageGrade()); | ||
| console.log("Średnia ocen z matmy:", student.getAverageGrade('maths')); | ||
| console.log("Średnia ocen z polski język:", student.getAverageGrade('polish')); | ||
| 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.
👍