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
58 changes: 57 additions & 1 deletion 01/assets/js/app.js
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;
Comment on lines +12 to +15
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 też sprawdzić czy konwersja jest tutaj niezbędna.

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');
}
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="/01/assets/js/app.js"></script>
</body>
</html>
31 changes: 28 additions & 3 deletions 02/app.js
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);
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: 39 additions & 3 deletions 03/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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 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="/04/js/app.js"></script>
</body>
</html>
41 changes: 41 additions & 0 deletions 04/js/app.js
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;
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 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);
45 changes: 45 additions & 0 deletions 05/app.js
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
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.

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;
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.

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);
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 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="/05/app.js"></script>
</body>
</html>