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
59 changes: 58 additions & 1 deletion 01/assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,61 @@
const a = '4.2';
const b = 9;

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

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

////operations
const addition = a + b
const subraction = a - b
const multiplication = a * b
const exponentiation = a**b
const division = a / b

function checkAddition(addition) {
const result = Boolean(addition === parseFloat(a) + parseFloat(b))
if(result) {
return addition
} else return parseFloat(a) + parseFloat(b)
}

function checkSubtraction(subtraction) {
const result = Boolean(subtraction === parseFloat(a) - parseFloat(b))
if(result) {
return subtraction
} else return parseFloat(a) - parseFloat(b)
}
function checkMultiplication(multiplication) {
const result = Boolean(multiplication === parseFloat(a) * parseFloat(b))
if(result) {
return multiplication
} else return parseFloat(a) * parseFloat(b)
}
function checkDivision(division) {
const result = Boolean(division === parseFloat(a) / parseFloat(b))
if(result) {
return division
} else return parseFloat(a) / parseFloat(b)
}
function checkExponation(exponentiation) {
const result = Boolean(exponentiation === parseFloat(a) ** parseFloat(b))
if(result) {
return exponentiation
} else return parseFloat(a) ** parseFloat(b)
}

function isBiggerthan20(result) {
if(result > 20) {
console.log('the result is bigger than 20')
} else console.log('the result is smaller than 20')
}

const allResults = [addition, subraction, multiplication, exponentiation, division]
allResults.forEach(function(result) {
isBiggerthan20(result)
})





1 change: 1 addition & 0 deletions 01/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="assets/js/app.js"></script>
<title>devmentor.pl - JS BASICS - #01</title>
</head>
<body>
Expand Down
31 changes: 29 additions & 2 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 < 10; i++) {
console.log(x + '*' + i + '=' + x * i)
}

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


/* rozwiązanie z pętlą while */
function exponentiation() {
const a = parseFloat(prompt('podaj podstawę potęgi!'))
const n = parseFloat(prompt('podaj wykładnik potęgi!'))

if(isNaN(a) || isNaN(n)) {
console.log('wrong input format')
return;
}
let counter = 1
let output = ''
while(counter <= n) {
if(counter == 1) {
output += a
} else if(counter > 1 && counter !== n){
output += '*' + a
} else {
output += '*' + a + '=' + a**n
}
counter++
}
console.log(output)
}

exponentiation()
1 change: 1 addition & 0 deletions 02/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="app.js"></script>
<title>devmentor.pl - JS BASICS - #02</title>
</head>
<body>
Expand Down
41 changes: 37 additions & 4 deletions 03/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,43 @@ const c = randomNumber(min, max);

console.log(a, b, c);





function getSum(num1, num2, num3) {
num1Int = parseInt(num1)
num2Int = parseInt(num2)
num3Int = parseInt(num3)

const numbers = [num1Int, num2Int, num3Int]
numbers.sort((a,b) => b - a)
const sum = numbers[0] + numbers[1]
return sum
}

const isEven = (num) => {
if(isNaN(num)){
return null
} else {
if(num % 2 === 0) {
return true
} else return false
}
}

function showInfo(sum,value) {
switch(value) {
case null:
console.log(`Podany argument ${sum} nie jest liczbą`)
break
case true:
console.log(`Podany argument ${sum} jest parzysty`)
break
case false:
console.log(`Podany argument ${sum} jest nieparzysty`)
}
}

const sum = getSum(a,b, c)
const even = isEven(sum)
showInfo(sum, even)


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

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

function arithmeticAvarage(array){
const arrayLength = array.length
const sum = array.reduce((acc, curr) => acc + curr)
const avarage = sum / arrayLength
return avarage
}

const RandomArray = createArray(10,200)
console.log(arithmeticAvarage(sortArray(RandomArray)))
1 change: 1 addition & 0 deletions 04/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="app.js"></script>
<title>devmentor.pl - JS BASICS - #04</title>
</head>
<body>
Expand Down
43 changes: 43 additions & 0 deletions 05/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
function Student(initFirstName, initLastName) {
this.firstName = initFirstName
thislastName = initLastName
this.grades = {}
}

Student.prototype.addGrade = function(subject, grade) {
if(typeof this.grades[subject] === 'undefined') {
this.grades[subject] = []
}
this.grades[subject].push(grade)
}

Student.prototype.getAvarageGrade = function(subject) {
if(subject !== undefined) {
const gradesNumber = this.grades[subject].length
const sum = this.grades[subject].reduce((acc, curr) => acc + curr)
const avarage = sum / gradesNumber
return avarage
} else {
let totalGrades = 0;
let totalSum = 0;
for(subj in this.grades) {
const grades = this.grades[subj].length
const sum = this.grades[subj].reduce((acc, curr) => acc + curr)
totalSum += sum;
totalGrades += grades
}
const overallAvarage = totalSum / totalGrades;
return overallAvarage;
}
}


const Student1 = new Student("Ala", "Sobota")
Student1.addGrade('math', 5)
Student1.addGrade('math', 5)
Student1.addGrade('math', 4)
Student1.addGrade('english', 4)
Student1.addGrade('biology', 3)
console.log(Student1.getAvarageGrade())
console.log(Student1)

1 change: 1 addition & 0 deletions 05/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="app.js"></script>
<title>devmentor.pl - JS BASICS - #05</title>
</head>
<body>
Expand Down