-
Notifications
You must be signed in to change notification settings - Fork 205
Zadania #153
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?
Zadania #153
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,60 @@ | ||
| const a = '4.2'; | ||
| const b = 9; | ||
|
|
||
| console.log(a, b); | ||
| console.log(a, b); | ||
|
|
||
|
|
||
|
|
||
| console.log(typeof a); | ||
| console.log(typeof b); | ||
|
|
||
| const sum = Number(a) + b; | ||
| const difference = Number(a) - b; | ||
| const multiplication = Number(a) * b; | ||
| const division = Number(a) / b; | ||
| const modulo = Number(a) % b; | ||
| const exponentiation = Math.pow(Number(a), b); | ||
|
|
||
|
|
||
| console.log("Suma: " + sum); | ||
| console.log("Różnica: " + difference); | ||
| console.log("Iloczyn: " + multiplication); | ||
| console.log("Iloraz: " + division); | ||
| console.log("Reszta: " + modulo); | ||
| console.log("Potęga: " + exponentiation); | ||
|
|
||
| if (sum > 20) { | ||
| console.log('Suma jest większa niż 20'); | ||
| } else { | ||
| console.log('Suma jest mniejsza lub równa 20'); | ||
| } | ||
|
|
||
| if (difference > 20) { | ||
| console.log('Różnica jest większa niż 20'); | ||
| } else { | ||
| console.log('Różnica jest mniejsza lub równa 20'); | ||
| } | ||
|
|
||
| if (multiplication > 20) { | ||
| console.log('Iloczyn jest większy niż 20'); | ||
| } else { | ||
| console.log('Iloczyn jest mniejszy lub równy 20'); | ||
| } | ||
|
|
||
| if (division > 20) { | ||
| console.log('Iloraz jest większy niż 20'); | ||
| } else { | ||
| console.log('Iloraz jest mniejszy lub równy 20'); | ||
| } | ||
|
|
||
| if (modulo > 20) { | ||
| console.log('Reszta jest większa niż 20'); | ||
| } else { | ||
| console.log('Reszta jest mniejsza lub równa 20'); | ||
| } | ||
|
|
||
| if (exponentiation > 20) { | ||
| console.log('Potęga jest większa niż 20'); | ||
| } else { | ||
| console.log('Potęga jest mniejsza lub równa 20'); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,32 @@ | ||
| // const x = prompt('Podaj liczbę'); | ||
|
|
||
| /* rozwiązanie z pętlą for */ | ||
| const x = 4; | ||
| // if (x >= 1 && x <= 9) { | ||
|
|
||
| // for (let i = 1; i <= 9; i++) { | ||
| // console.log(x + " x " + i + " = " + (x * i)); | ||
| // } | ||
| // } else { | ||
| // console.log('Podana liczba jest poza zakresem! Proszę podać liczbę od 1 do 9.'); | ||
| // } | ||
|
|
||
| /* rozwiązanie z pętlą while */ | ||
|
|
||
| let a = prompt("Podaj podstawę"); | ||
| let n = prompt("Podaj wykładnik"); | ||
|
|
||
| /* rozwiązanie z pętlą while */ | ||
| let result = 1; | ||
|
|
||
| let i = 0; | ||
| let str=''; | ||
| while (i < n) { | ||
| result = result * a; | ||
| i=i+1; | ||
| if (i===1) { | ||
| str=str+a | ||
| } | ||
| else { | ||
| str=str+'*'+a | ||
| } | ||
| } | ||
| console.log(str); | ||
| console.log(str+'='+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,12 +7,48 @@ const c = randomNumber(min, max); | |
|
|
||
| console.log(a, b, c); | ||
|
|
||
|
|
||
|
|
||
| const result = getSum(a,b,c); | ||
| console.log(result); | ||
|
|
||
|
|
||
|
|
||
|
|
||
| function randomNumber(min, max) { | ||
| return Math.round((Math.random() * (max - min)) + min); | ||
| } | ||
| } | ||
| function getSum(x,y,z) { | ||
| const intX=parseInt(x); | ||
| const intY=parseInt(y); | ||
| const intZ=parseInt(z); | ||
| const arr=[intX, intZ, intY]; | ||
| arr.sort(function(a,b){ | ||
| return a-b; | ||
| }) | ||
| console.log(arr) | ||
| return arr[1]+arr[2]; | ||
| } | ||
| const isEven = function(number) { | ||
|
|
||
| if (typeof number !== 'number') { | ||
| return null; | ||
| } | ||
|
|
||
| return number % 2 === 0; | ||
| }; | ||
| function showInfo(value, itResult) { | ||
| switch (itResult) { | ||
|
|
||
| case null: | ||
| console.log("Podany argument " + value + " nie jest liczbą"); | ||
| break; | ||
| case true: | ||
| console.log("Podany argument " + value + " jest parzysty"); | ||
| break; | ||
| case false: | ||
| console.log("Podany argument " + value + " jest nieparzysty"); | ||
| break; | ||
| } | ||
| } | ||
| const itResult = isEven(result); | ||
|
|
||
| showInfo(result, itResult); | ||
|
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,41 @@ | ||
|
|
||
| function createArray(min, max) { | ||
| const array = []; | ||
|
|
||
| for (let i = 0; i < 20; i++) { | ||
| const randNumber = Math.round((Math.random() * (max - min)) + min) | ||
| array.push(Math.round(randNumber)); | ||
| } | ||
| return array; | ||
|
|
||
| } | ||
| const arr = createArray(1, 100); | ||
| console.log(arr) | ||
|
|
||
| function getLargest (numbers) { | ||
| numbers.sort(function (a,b) { | ||
| return b-a; | ||
|
|
||
| }) | ||
| const largest = numbers.slice(0,10); | ||
| return largest; | ||
| } | ||
| const largest = getLargest(arr); | ||
| console.log(largest); | ||
|
|
||
| function getAvg(arr) { | ||
| const sum = arr.reduce(function (accumulator, currentValue) { | ||
| return accumulator + currentValue; | ||
| }, 0); | ||
| return sum / 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 sprawdzać czy tablica posiada jakieś elementy, bo wtedy dzielimy przez 0 :P |
||
| } | ||
|
|
||
| const average = getAvg(arr); | ||
| console.log(average); | ||
|
|
||
| const arr2 = createArray(10, 200); | ||
| console.log(arr2); | ||
| const largest2 = getLargest(arr2); | ||
| console.log(largest2); | ||
| const average2 = getAvg(arr2); | ||
| console.log(average2); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| 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); | ||
|
Comment on lines
+9
to
+10
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. Uwaga na odstępy od lewej krawędzi |
||
| }; | ||
|
|
||
| Student.prototype.getAverageGrade = function (subject) { | ||
|
|
||
| if (typeof subject !== 'undefined') { | ||
| const grades = this.grades[subject]; | ||
| const sum = grades.reduce(function (acc, grade) { | ||
| return acc + grade; | ||
| }, 0); | ||
|
|
||
| return sum / grades.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. Podobnie jak w poprzednim zadaniu - nie dzielimy przez 0 :P |
||
| } | ||
|
|
||
| const allGrades = Object.values(this.grades).reduce(function (acc, grades) { | ||
| return acc.concat(grades); | ||
| }, []); | ||
|
|
||
| const totalSum = allGrades.reduce(function (acc, grade) { | ||
| return acc + grade; | ||
| }, 0); | ||
| return totalSum / allGrades.length; | ||
| }; | ||
|
|
||
|
|
||
| //Przykład użycia | ||
| const student = new Student('Jan', 'Kowalski'); | ||
| student.addGrade('maths', 1); | ||
| student.addGrade('maths', 5); | ||
| student.addGrade('english', 4); | ||
|
|
||
| const avgMath = student.getAverageGrade('maths'); | ||
| const avg = student.getAverageGrade(); | ||
|
|
||
| console.log(avgMath); | ||
| console.log(avg); | ||
|
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 - #05</title> | ||
| </head> | ||
| <body> | ||
|
|
||
| <script src="/05/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.
Warto też sprawdzić czy konwersja jest tutaj niezbędna.