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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5502
}
69 changes: 68 additions & 1 deletion 01/assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,71 @@
const a = '4.2';
const b = 9;

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

const numA = parseFloat(a);

const res1 = numA + b;
const res2 = numA - b;
const res3 = numA * b;
const res4 = numA / b;
const res5 = numA % b;
let res6 = numA ;
res6++;
let res7 = b;
res7++;
let res8 = numA ;
res8--;
let res9 = b;
res9--;

// if(res1 > 20) {
// console.log('Wynik ' + res1 + ' jest wiekszy od 20!');
// } else {
// console.log('Wynik ' + res1 + ' nie jest większy od 20!');
// }

// if(res2 > 20) {
// console.log('Wynik ' + res2 + ' jest wiekszy od 20!');
// } else {
// console.log('Wynik ' + res2 + ' nie jest większy od 20!');
// }

// if(res3 > 20) {
// console.log('Wynik ' + res3 + ' jest wiekszy od 20!');
// } else {
// console.log('Wynik ' + res3 + ' nie jest większy od 20!');
// }

// if(res4 > 20) {
// console.log('Wynik ' + res4 + ' jest wiekszy od 20!');
// } else {
// console.log('Wynik ' + res4 + ' nie jest większy od 20!');
// }

// if(res5 > 20) {
// console.log('Wynik ' + res5 + ' jest wiekszy od 20!');
// } else {
// console.log('Wynik ' + res5 + ' nie jest większy od 20!');
// }


// console.log(res1, res2, res3, res4, res5, res6, res7, res8, res9);


function checkResult(resultNumber, result) {
if(result > 20) {
console.log(resultNumber + ' jest większy od 20!');
} else {
console.log(resultNumber + ' nie jest większy od 20!');
}
}

checkResult(`Wynik ${res1}`, res1);
checkResult(`Wynik ${res2}`, res2);
checkResult(`Wynik ${res3}`, res3);
checkResult(`Wynik ${res4}`, res4);
checkResult(`Wynik ${res5}`, res5);

17 changes: 14 additions & 3 deletions 01/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
<!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 - #01</title>
</head>

<body>



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

</html>
38 changes: 36 additions & 2 deletions 02/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@

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

// if(x >= 1 && x <= 9) {
// for(let i=1; i<=9; i++) {
// const result = x * i;
// console.log(x + ' x ' + i + ' = ' + result);
// }
// } else {
// console.log(alert('Podałeś niepoprawną liczbę!'));
// }


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

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


if(a > 0 && n > 0) {
let result = 1
let counter = 1
let showCalculation = ''

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

if(counter === 1) {
showCalculation = showCalculation + a
} else {
showCalculation = showCalculation + ' * ' + a
}

counter++
}

console.log(showCalculation + ' = ' + result);
} else {
console.log(alert('Podaj liczbę większą od 0'));
}
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.

👍

17 changes: 14 additions & 3 deletions 02/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
<!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 - #02</title>
</head>

<body>



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

</html>
56 changes: 55 additions & 1 deletion 03/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,58 @@ console.log(a, b, c);

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


function getSum(a, b, c) {
const num1 = Math.floor(a)
const num2 = Math.floor(b)
const num3 = Math.floor(c)

let largestNumber = Math.max(num1, num2, num3)
let middleNumber

if(largestNumber === num1) {
middleNumber = Math.max(num2, num3)
} else if (largestNumber === num2) {
middleNumber = Math.max(num1, num3)
} else {
middleNumber = Math.max(num1, num2)
}
return largestNumber + middleNumber
Comment on lines +26 to +36
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.

Lepiej by było wrzucić do tablicy, posortować i mamy dwie największe dużo prościej :)

}



const isEven = function(number) {
if(typeof number !== 'number') {
return null
}
return number % 2 === 0
}



function showInfo(anyValue, specificValue) {
switch(specificValue) {
case null:
console.log('Podany argument ' + anyValue + ' nie jest liczbą!');
break
case true:
console.log('Podany argument ' + anyValue + ' jest parzysty!');
break
case false:
console.log('Podany argument ' + anyValue + ' jest nieparzysty!');
break
default:
console.log('Nieprawidłowa wartość!');
}
}

const sum = getSum(a, b, c)
console.log(sum);

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

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.

👍

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="script.js"></script>
</body>

</html>
52 changes: 52 additions & 0 deletions 04/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict'

function createArray(min, max) {
const newArray = []

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

return newArray

}


function get10LargestNumbers(array) {
const sortedArray = array.sort(function(a, b)
{
return b - a
});

return sortedArray.slice(0, 10)

}


function calculateAverage(array) {
if(array.length === 0) {
return 0
}

const sumArrNumbers = array.reduce(function(acc, currentValue) {
return acc + currentValue
}, 0)

return sumArrNumbers / array.length
}



const min = 10
const max = 200

const array = createArray(min, max)
console.log('Wygenerowana tablica: ' + array);

const largestNumbers = get10LargestNumbers(array)
console.log('10 największych liczb z tablicy: ' + largestNumbers);

const average = calculateAverage(largestNumbers)
console.log('Średnia arytmetyczna 10-ciu największych liczb z tablicy: ' + average);

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.

👍

17 changes: 14 additions & 3 deletions 05/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
<!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="script.js"></script>
</body>

</html>
Loading