-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
61 lines (61 loc) · 2.22 KB
/
main.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
document.getElementById("op").value = ""
document.getElementById("calc").onclick = function() {
var fnum = Number(document.getElementById("fn").value);
var oper = document.getElementById("op").value;
var senum = Number(document.getElementById("sn").value);
console.log(fnum);
console.log(oper);
console.log(senum);
if (oper == "+") {
var result = fnum + senum;
console.log(result);
document.getElementById("header").innerHTML = result
document.getElementById("calcstat").innerHTML = "Calculated!"
}
else if (oper == "-") {
var result = fnum - senum;
console.log(result);
document.getElementById("header").innerHTML = result
document.getElementById("calcstat").innerHTML = "Calculated!"
}
else if (oper == "/") {
var result = fnum / senum;
console.log(result);
document.getElementById("header").innerHTML = result
document.getElementById("calcstat").innerHTML = "Calculated!"
}
else if (oper == "+") {
var result = fnum + senum;
console.log(result);
document.getElementById("header").innerHTML = result
document.getElementById("calcstat").innerHTML = "Calculated!"
}
else if (oper == "*") {
var result = fnum * senum;
console.log(result);
document.getElementById("header").innerHTML = result
document.getElementById("calcstat").innerHTML = "Calculated!"
}
else if (oper == "x") {
var result = fnum * senum;
console.log(result);
document.getElementById("header").innerHTML = result
document.getElementById("calcstat").innerHTML = "Calculated!"
}
else if (oper == "%") {
var result = fnum % senum;
console.log(result);
document.getElementById("header").innerHTML = result
document.getElementById("calcstat").innerHTML = "Calculated!"
}
else {
document.getElementById("calcstat").innerHTML = "Please enter a proper operator and/or number."
}
};
document.getElementById("reset").onclick = function () {
document.getElementById("fn").value = ""
document.getElementById("op").value = ""
document.getElementById("sn").value = ""
document.getElementById("header").innerHTML = "Calculator"
document.getElementById("calcstat").innerHTML = ""
}