-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise_02.html
More file actions
64 lines (52 loc) · 1.83 KB
/
Exercise_02.html
File metadata and controls
64 lines (52 loc) · 1.83 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calculator</title>
</head>
<body>
<script>
// addition function
add = (num1, num2) => alert(num1+ '+' + num2 + ' = '+ (num1 + num2));
// subtraction function
sub = (num1, num2) => alert(num1+ '-' + num2 + ' = '+ (num1 - num2));
// multiplication function
mul = (num1, num2) => alert(num1+ '*' + num2 + ' = '+ (num1 * num2));
// division function
div = (num1, num2) => alert(num1+ '/' + num2 + ' = '+ (num1 / num2));
// calling calc function
calc();
function calc(){
var value1 = Number(prompt('enter first number'));
var value2 = Number(prompt('enter second number'));
do{
var operation = Number(prompt ('select operation to perform:\n 1. Addition\n 2. subtraction\n 3. multiplication\n 4. Division'));
if(operation===1){
add(value1, value2);
}
else if(operation===2){
sub(value1, value2);
}
else if(operation===3){
mul(value1, value2);
}
else if(operation===4){
div(value1, value2);
}
else{
alert('please select an operation!');
}
}
while(!operation);
var check = confirm('would you like to carry out another operation?');
if(check){
calc();
}
else{
alert('you clicked cancel, bye!');
}
}
</script>
</body>
</html>