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
80 changes: 78 additions & 2 deletions 01/assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,80 @@
const a = '4.2';
const b = 9;
const b = 20;
const c = parseFloat(a);

console.log(a, b);
console.log(typeof a);
console.log(typeof b);

const addVariable = c + b;
console.log(addVariable);

const concatVariable = a + b;
console.log(concatVariable);

const subtractVariable = a - b;
console.log(subtractVariable);

const multiVariable = a * b;
console.log(multiVariable);

const divideVariable = a / b;
console.log(divideVariable);

const modVariable = Number(a) % b;
console.log(modVariable);

let incrementVar = a;
incrementVar++;
console.log(incrementVar);

let decrementVar = b;
decrementVar--;
console.log(decrementVar);


if (addVariable > 20) {
console.log('a+b jest wieksze od 20')
} else {
console.log('a+b jest mniejsze od 20')
}

if (subtractVariable > 20) {
console.log('a-b jest wieksze od 20')
} else {
console.log('a-b jest mniejsze od 20')
}

if (multiVariable > 20) {
console.log('a*b jest wieksze od 20')
} else {
console.log('a*b jest mniejsze od 20')
}

if (divideVariable > 20) {
console.log('a/b jest wieksze od 20')
} else {
console.log('a/b jest mniejsze od 20')
}

if (modVariable > 20) {
console.log('a%b jest wieksze od 20')
} else {
console.log('a%b jest mniejsze od 20')
}

if (incrementVar > 20) {
console.log('a++ jest wieksze od 20')
} else {
console.log('a++ jest mniejsze od 20')
}

if (decrementVar > 20) {
console.log('a-- jest wieksze od 20')
} else {
console.log('a-- jest mniejsze od 20')
}

console.log();
console.log();
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.

👍


console.log(a, b);
2 changes: 1 addition & 1 deletion 01/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<title>devmentor.pl - JS BASICS - #01</title>
</head>
<body>

,<script src="./assets/js/app.js"></script>
</body>
</html>
39 changes: 37 additions & 2 deletions 02/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@

/* rozwiązanie z pętlą for */
const x = 4;
const x = prompt('Podaj liczbe z przedzialu od 1 do 9!');
let result;

for (let i = 1; i <= 9; i++) {
if (x <= 9 && x > 0) {
result = i * x;
console.log(x + ' x ' + i + ' = ' + result);
} else {

alert('Wybrana liczba nie jest z przedzialu 1-9');

}
}

/* rozwiązanie z pętlą while */

const a = parseInt(prompt('Podaj liczbe z przedzialu od 1 do 9'));
const n = parseInt(prompt('Podaj liczbe z przedzialu od 1 do 9'));
let result2 = 1
// console.log(result)


let j = 0;
let str = '';
if (a <= 9 && a > 0 && n <= 9 && n > 0) {
while (j < n) {
j++;
if (n === j) {
str += a;
} else {
str += a + '*';
}
}
console.log(str + '=' + Math.pow(a, n));
}
else {
alert('Wybrana liczba nie jest z przedzialu 1-9');
}


/* rozwiązanie z pętlą while */
4 changes: 2 additions & 2 deletions 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>

</body>
<script src='./app.js'></script>
</body>
</html>
66 changes: 48 additions & 18 deletions 03/app.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,48 @@
const min = 1;
const max = 100;

const a = randomNumber(min, max);
const b = randomNumber(min, max);
const c = randomNumber(min, max);

console.log(a, b, c);







function randomNumber(min, max) {
return Math.round((Math.random() * (max - min)) + min);
}
const a = 41.5234;
const b = 25;
const c = 14;

const sum = getSum(a, b, c);


function getSum(a, b, c) {
let largestNum = Math.max(a, b, c);
let secondLargestNum;

if (largestNum === a) {
secondLargestNum = Math.max(b, c);
} else if (largestNum === b) {
secondLargestNum = Math.max(a, c);
} else {
secondLargestNum = Math.max(a, b);
}
return sum1 = parseInt(largestNum) + parseInt(secondLargestNum);
}

const even = isEven(2);

function isEven(num) {
if (typeof num !== "number") {
return null;
} else if (num % 2 === 0) {
return true;
} else {
return false;
}
}

function showInfo(para1, para2) {
switch (para2) {
case null:
console.log('Podany argument ' + para1 + ' nie jest liczbą');
break;
case true:
console.log('Podany argument ' + para1 + ' jest parzystybą');
break;
case false:
console.log('Podany argument ' + para1 + ' jest nieparzysty');
break;
}
}

showInfo(sum, even);
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.

👍

43 changes: 43 additions & 0 deletions 04/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
function createArray(min, max) {
const arr = [];
for (let i = 1; i <= 20; i++) {
const randomNumber = Math.floor(Math.random() * (max - min + 1)) + min;
arr.push(randomNumber);
}
return arr;
}

const arr = createArray(10, 200);
console.log(arr);



function getLargest() {
arr.sort(function (a, b) {
return b - a;
});
return arr.slice(0, 10);

}
const largest = getLargest(arr);
console.log(largest);



function getAvg(arr) {
if (arr.length === 0) {
return 0;
}
let sum = 0;
arr.forEach(num => {
sum += num;
});
return sum / 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 się zabezpieczyć czy nie dzielimy przez 0 :)


}

const avg = getAvg(largest);
console.log(avg);



15 changes: 12 additions & 3 deletions 04/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<!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">
<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>
74 changes: 74 additions & 0 deletions 05/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Tym razem stworzysz konstruktor, na podstawie którego będzie można generować obiekt przechowujący informacje o studencie.

// Wymagania:
// 1. Obiekt posiada imię i nazwisko przekazywane podczas inicjalizacji (przy użyciu `new`).

function Student(initFirstName, initLastName) {
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);
};

// 2. Konstruktor:
// - udostępnia metody (przez `prototype`),
// - metody te pozwalają:
// - dodać ocenę z danego przedmiotu,
// - obliczyć średnią arytmetyczną z konkretnego przedmiotu,
// - obliczyć ogólną średnią arytmetyczną.

Student.prototype.getAverageGrade = function (subject) {
if (typeof subject !== 'undefined') {
const grades = this.grades[subject];
if (!grades || grades.length === 0) return null;
console.log(grades);
let sum = 0;
for (let i = 0; i < grades.length; i++) {
sum += grades[i];
}
return (sum / grades.length);
}

let totalSum = 0;
let totalCount = 0;
console.log(this.grades);
for (let subjectName in this.grades) {
const subjectGrades = this.grades[subjectName];
console.log(subjectGrades);
for (let i = 0; i < subjectGrades.length; i++) {
totalSum += subjectGrades[i];
totalCount++;
}
}
if (totalCount === 0) return null;

return ((totalSum / totalCount).toFixed(2));
}

const maths = 4;

const student = new Student('Jan', 'Kowalski');
console.log(student)
student.addGrade('maths', 4);
student.addGrade('maths', 6);
student.addGrade('english', 3);
const avgMath = student.getAverageGrade('maths'); // 5
const avg = student.getAverageGrade(); // 4.33

console.log(avgMath);
console.log(avg)


// Zwróć uwagę, że pobranie informacji o ocenach z konkretnego przedmiotu może się odbywać w ten sposób:
// ```
// const subject = 'maths';
// const grades = this.grades[subject];
// ```

15 changes: 12 additions & 3 deletions 05/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<!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">
<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>