-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathscript.js
More file actions
51 lines (47 loc) · 1.31 KB
/
script.js
File metadata and controls
51 lines (47 loc) · 1.31 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
var operand = null;
var operation = null;
var n = false;
function prnt(c) {
if(n) {
document.getElementById("calcScreen").innerHTML = c;
n = false;
} else {
document.getElementById("calcScreen").innerHTML = document.getElementById("calcScreen").innerHTML + c;
}
}
function result() {
if (operand === null || operation === null || document.getElementById("calcScreen").innerHTML === "") {
alert("Нечего считать!");
return;
}
other_operand = document.getElementById("calcScreen").innerHTML - 0;
r = 0;
switch (operation) {
case "addition":
r = +operand + other_operand;
break;
case "subtraction":
r = operand - other_operand;
break;
case "multiplication":
r = operand * other_operand;
break;
case "division":
r = operand / other_operand;
break;
}
return r;
}
function calc(o) {
if(operand !== null && operation !== null) {
document.getElementById("calcScreen").innerHTML = result();
}
operand = document.getElementById("calcScreen").innerHTML;
operation = o;
n = true;
}
function reset() {
document.getElementById("calcScreen").innerHTML = "";
operand = null;
operation = null;
}