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
Binary file added .DS_Store
Binary file not shown.
50 changes: 49 additions & 1 deletion 01/assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,52 @@
const a = '4.2';
const b = 9;

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

function performAction(number1, number2, mathOperation) {

const numA = parseFloat(number1);
const numB = parseFloat(number2);

switch (mathOperation) {
case '+':
result = numA + numB;
break;

case '-':
result = numA - numB;
break;

case '*':
result = numA * numB;
break;

case '/':
result = numA / numB;
break;

case '%':
result = numA % numB;
break;

default:
result = 'Niepoprawna operacja';
}

if (result > 20){
console.log('Wynik operacji jest większy od 20')
} else if (result === 20) {
console.log('Wynik operacji wynosi 20');
} else {
console.log('Wynik operacji jest mniejszy od 20')
}

return result;
}

console.log(performAction(a, b, '+'));
console.log(performAction(a, b, '-'));
console.log(performAction(a, b, '*'));
console.log(performAction(a, b, '/'));
console.log(performAction(a, b, '%'));
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 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: 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 = prompt('Podaj liczbę!');

// if (x > 9 || x < 1){
// alert('Wartość powinna mieścić się w przedziale 1-9! Podaj cyfrę!');
// location.reload();
// }

// for (let i = 0; i < 10; i++){
// console.log(`${x} * ${i} = ${x*i}`);
// }


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

const a = prompt('Podaj podstawę!');
const n = prompt('Podaj wykładnik!');

if (a > 9 || a < 0 || n < 0 || n > 10){
alert('Wartość powinna mieścić się w przedziale 1-9! Podaj cyfrę!');
location.reload();

} else if (n == 0) {
console.log(`${a}^${n} = 1`);
//zostawilem w tym przypadku zapis a^n, poniewaz a^0 = 1, ciezko to inaczej zapisac
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.

👍


} else {

let i = 1;
let sum = a;
let equation = `${a}`
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 po prostu zapisać let equation = a


while (i < n){
sum *= a;
equation += ` * ${a}`;
i++;
}

/* rozwiązanie z pętlą while */
console.log(`${equation} = ${sum}`);
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>
49 changes: 46 additions & 3 deletions 03/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,55 @@ const c = randomNumber(min, max);

console.log(a, b, c);

function randomNumber(min, max) {
return Math.round((Math.random() * (max - min)) + min);
}

function getSum(a, b, c) {

const array = [parseInt(a), parseInt(b), parseInt(c)];
const sortedArray = array.sort((a ,b) => b - a);
const arrayWith2Elements = sortedArray.slice(0, 2);
const sum = arrayWith2Elements.reduce((acc, el) => acc + el, 0);
return sum;
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.

👍


}


const isEven = function(number){

if (typeof(number) !== 'number'){
return null;
}

function randomNumber(min, max) {
return Math.round((Math.random() * (max - min)) + min);
}
if(number%2 === 0){
return true;
} else {
return false;
}
}

function showInfo(value, boolean){

switch(value, boolean){
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 sum = getSum(a, b, c);
console.log(sum);

const isSumEven = isEven(sum);
console.log(isSumEven);

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.

👍

33 changes: 33 additions & 0 deletions 04/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function createArray(min, max){

const array = [];

for (let i = 0; i < 20; i++){
const randomNumber = Math.round((Math.random() * (max - min)) + min);
array.push(randomNumber);
}

return array;
}

function sortArray(array){
const sortedArray = array.sort((a, b) => b - a);
const highestNumbers = sortedArray.slice(0, 10);
return highestNumbers;
}

function getAvg(array){
const sum = array.reduce((acc, element) => acc + element, 0);
const avg = sum / array.length;
return avg;
}

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

const sort = sortArray(arr);
console.log(sort);

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

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>
42 changes: 42 additions & 0 deletions 05/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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){

if(typeof this.grades[subject] === 'undefined') {

const allGrades = Object.values(this.grades).flat();
const generalSum = allGrades.reduce((acc, element) => acc + element);
const generalAvg = (generalSum / allGrades.length).toFixed(2);
return generalAvg;
}

const sum = this.grades[subject].reduce((acc, element) => acc + element);
const avg = sum / this.grades[subject].length;
return avg;
}

const student = new Student('Jan', 'Kowalski');
student.addGrade('math', 4);
student.addGrade('math', 6);
student.addGrade('english', 3);

const avgMath = student.getAverageGrade('math');
console.log(avgMath);

const avg = student.getAverageGrade();
console.log(avg);

console.log(student);
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="./app.js"></script>
</body>
</html>