-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.js
86 lines (57 loc) · 1.83 KB
/
events.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Funkce
function greetings() {
console.log("Hello world!");
}
;
// greetings();
function secti(cislo1, cislo2) {
let soucet = cislo1 + cislo2;
return soucet;
}
// console.log(secti (5, 8));
function obarviNaCerveno() {
// ziskat element obdelniku (to get the element)
let obdelnik = document.querySelector(".obdelnik");
// obarvit na cerveno (to color the element)
obdelnik.style.backgroundColor = "darkred";
}
// obarviNaCerveno();
function obarviNaModro() {
// ziskat element obdelniku (to get the element)
let obdelnik = document.querySelector(".obdelnik");
// obarvit na cerveno (to color the element)
obdelnik.style.backgroundColor = "blue";
}
// obarviNaModro();
// Task 1: Write a function that colors a rectangle with a color chosen by the user.
function colorRectangle(color) {
let rectangle = document.querySelector(".obdelnik");
rectangle.style.backgroundColor = color;
}
// colorRectangle("pink");
// Task 2: Write a function calculator that takes 2 arguments (2 numbers).
// The function will also take from the user which type of mathematical operation
// to perform on these two numbers. (The user will enter the operation symbol +, -, *.)
// Using an if-else block, determine which operation needs to be performed,
// and provide the result of the operation to the user using an "alert".
function myCalculator(num1, num2, operation) {
// Variable to store the result
let result;
//what operation to perform
if (operation === "+"){
result = num1 + num2;
} else if (operation === "-"){
result = num1 - num2;
} else if (operation === "*"){
result = num1*num2;
} else if (operation === "/"){
result = num1/num2;
} else {
alert("Invalid operation!");
return;
}
alert("The result is: " + result)
}
//e.g.
// myCalculator(5, 10, "+");
// Události