Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion 01/assets/js/app.js
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
);
Comment on lines +18 to +26
Copy link
Copy Markdown
Owner

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


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');
}
5 changes: 4 additions & 1 deletion 01/index.html
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>
39 changes: 36 additions & 3 deletions 02/app.js
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);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

6 changes: 5 additions & 1 deletion 02/index.html
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>
49 changes: 42 additions & 7 deletions 03/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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);
}
28 changes: 28 additions & 0 deletions 04/app.js
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;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warto pamiętać o drugim parametrze tj. reduce(() => {}, 0) - wtedy pusta tablica nie powoduje błędu

}

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;
}
5 changes: 4 additions & 1 deletion 04/index.html
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>
38 changes: 38 additions & 0 deletions 05/app.js
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());
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

5 changes: 4 additions & 1 deletion 05/index.html
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>