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
48 changes: 45 additions & 3 deletions 01/assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,46 @@
const a = '4.2';
const b = 9;
let a = '4.2';
let b = 9;

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

const concat = a + b;
// console.log('Wynik konkatenacji:', concat);

a = parseFloat(a);

const add = a + b;
// console.log('Wynik dodawania:', add);

const substract = a - b;
// console.log('Wynik odejmowania:', substract);

const multipli = a * b;
// console.log('Wynik mnozenia:', multipli);

const divide = a / b;
// console.log('Wynik dzielenia:', divide);

const modulo = a % b;
// console.log('wynik reszty z dzielenia:', modulo);

const inc = ++a;
// console.log('Wynik inkrementacji:', inc);

const dec = --b;
// console.log('Wynik dekremenmtacji:', dec);

const arr = [concat, add, substract, multipli, divide, modulo, inc, dec];

const isBigger = [];
const isSmaller = [];

const checkResult = arr.map((item) => {
if (item > 20) {
isBigger.push(item);
} else if (item < 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.

👍

isSmaller.push(item);
}
});

console.log('Wyniki działan większy niz 20', isBigger);
console.log('Wynik dzialan mniejszy niz 20', isSmaller);
18 changes: 9 additions & 9 deletions 01/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!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">
<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>

</body>
</html>
</head>
<body>
<script src="./assets/js/app.js"></script>
</body>
</html>
33 changes: 30 additions & 3 deletions 02/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@

/* rozwiązanie z pętlą for */
const x = 4;
// const x = prompt('Podaj liczbę!');

// for (let i = 1; i <= 9; i++) {
// const result = x * i;

// if (x > 0 && x < 10) {
// console.log(`${x} x ${i} = ${result}`);
// } else {
// console.log('Liczba nie mieści się w przedziale od 1 do 9');
// }
// }

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

let a = 3; //podstawa
let n = 4; //wykładnik

let counter = 0;
let result = 1;
let displayString = '';

while (counter < n) {
counter++;
result = result * a;

if (counter === 1) {
displayString = `${a}`;
} else {
displayString = `${displayString} * ${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.

👍

}

/* rozwiązanie z pętlą while */
console.log(`${displayString} = ${result}`);
18 changes: 9 additions & 9 deletions 02/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!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">
<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>

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

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

console.log(a, b, c);
function randomNumber(min, max) {
return Math.round(Math.random() * (max - min) + min);
}

const getSum = (a, b, c) => {
a = parseInt(a);
b = parseInt(b);
c = parseInt(c);

const arr = [a, b, c];

const arrSort = arr.sort();
const twoBiggest = arrSort.slice(1);

const initVal = 0;
const sumWithInitVal = twoBiggest.reduce((acc, curr) => acc + curr, initVal);

return sumWithInitVal;
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 (sum) {
if (typeof sum === typeof number) {
return null;
} else if (sum % 2 === 0) {
return true;
}

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

const showInfo = (num, bool) => {
const messages = {
null: `Podany arguments ${num} nie jest liczbą`,
true: `Podany arguments ${num} jest parzysty`,
false: `Podany arguments ${num} jest nieparzysty`,
};

const randomBool = messages[bool];
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.

Teraz już nie potrzebujemy switch-a, rozwiązanie jest już dostępne w randomBool :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

O, wow :o

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.

:)


return randomBool;
};

const sum = getSum(a, b, c);
const even = isEven(sum);
const show = showInfo(sum, even);
77 changes: 77 additions & 0 deletions 04/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// 1.

const createArray = (a, b) => {
const emptyArr = [];

for (let i = 0; i < 20; i++) {
let randomNumbers = Math.round(Math.random() * (b - a) + a);
emptyArr.push(randomNumbers);
}
return emptyArr;
};

const arr = createArray(1, 100);
console.log('Tworzymy tablice:', arr);

// 2.

const getLargest = function (arrToSort) {
const sortArr = arrToSort.sort(function (a, b) {
return b - a;
});

const theBiggestNumbers = sortArr.slice(-20, 10);
return theBiggestNumbers;
};

const largest = getLargest(arr);
console.log('Wybieramy 10 największych liczb z posortowanej malejąco tablicy:', largest);

// 3.
const getAvg = (arr) => {
const initValue = 0;
const sumWithInitValue = arr.reduce((acc, currValue) => acc + currValue, initValue);

const arithmeticAvg = sumWithInitValue / arr.length;

return arithmeticAvg;
};

const avg = getAvg([1, 2, 3, 4, 5]);
console.log('Średnia arytmetyczna tablicy:', avg);

4;

const getArr = (a, b) => {
const emptyArray = [];

for (let i = 0; i < 20; i++) {
let randomNum = Math.round(Math.random() * (b - a) + a);
emptyArray.push(randomNum);
}

return emptyArray;
};

const newArr = getArr(10, 200);
console.log('Nowa tablica:', newArr);

const getTenBiggest = (sortNumbers) => {
const sortArr = sortNumbers.sort(function (a, b) {
return b - a;
});

const getBiggestTen = sortArr.slice(-20, 10);
console.log(getBiggestTen);

initValue = 0;
const sumBiggestTen = getBiggestTen.reduce((acc, curr) => acc + curr, initValue);
console.log(sumBiggestTen);
const avgBiggestTen = sumBiggestTen / getBiggestTen.length;
console.log(avgBiggestTen);

return avgBiggestTen;
};

const biggestTen = getTenBiggest(newArr);
console.log('Średnia arytmetyczna 10 największych liczb:', biggestTen);
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.

👍

58 changes: 58 additions & 0 deletions 05/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
function Student(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
this.grades = {};
}

Student.prototype.addGrade = function (subjectName, grade) {
const subject = subjectName;
const grades = this.grades[subject];

if (typeof this.grades[subject] === 'undefined') {
this.grades[subject] = [];
}
this.grades[subject].push(grade);
};

const getAvgCalc = function (gradesArray) {
const initVal = 0;
const sumWithInit = gradesArray.reduce((acc, curr) => acc + curr, initVal);
const avgCalc = sumWithInit / gradesArray.length;

return avgCalc;
};

Student.prototype.getAverageGrade = function (gradeKey) {
const subject = gradeKey;
const grades = this.grades[subject];

const gradesVal = Object.values(this.grades);
const allGrades = [];

for (let i = 0; i < gradesVal.length; i++) {
let grade = gradesVal[i];
for (let j = 0; j < grade.length; j++) {
allGrades.push(grade[j]);
}
}

if (subject) {
return grades;
} else {
return allGrades;
}
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 student = new Student('Jan', 'Kowalski');

student.addGrade('maths', 4);
student.addGrade('maths', 6);
student.addGrade('english', 3);
// const avgMath = student.getAverageGrade('maths');
const avg = student.getAverageGrade();
const weird = getAvgCalc(avg);

console.log(student);
// console.log(avgMath);
console.log(avg);
console.log(weird);