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
73 changes: 72 additions & 1 deletion 01/assets/js/app.js
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`)
}
}
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.

👍

3 changes: 2 additions & 1 deletion 01/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="./assets/css/style.css">
<title>devmentor.pl - JS BASICS - #01</title>
</head>
<body>

<script src="./assets//js/app.js"></script>
</body>
</html>
34 changes: 32 additions & 2 deletions 02/app.js
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}`);
}
}
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.

👍



/* 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}`);
}
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.

👍


2 changes: 1 addition & 1 deletion 02/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<title>devmentor.pl - JS BASICS - #02</title>
</head>
<body>

<script src="./app.js"></script>
</body>
</html>
42 changes: 38 additions & 4 deletions 03/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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.

👍



function randomNumber(min, max) {
Expand Down
28 changes: 28 additions & 0 deletions 04/app.js
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)}`);
2 changes: 1 addition & 1 deletion 04/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<title>devmentor.pl - JS BASICS - #04</title>
</head>
<body>

<script src="./app.js"></script>
</body>
</html>
41 changes: 41 additions & 0 deletions 05/app.js
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]);
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.

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'));
2 changes: 1 addition & 1 deletion 05/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<title>devmentor.pl - JS BASICS - #05</title>
</head>
<body>

<script src="./app.js"></script>
</body>
</html>