-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
79 lines (68 loc) · 2.51 KB
/
script.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
var smallDisplayValue = "";
var displayValue;
function updateAllDisplays(dis, small_dis) {
small_dis = small_dis.replace("/", "÷");
small_dis = small_dis.replace("*", "×");
document.getElementById("display_bar_p").innerHTML = dis;
document.getElementById("small_display_bar_p").innerHTML = small_dis;
}
function updateDisplay(inputNumber) {
displayValue = document.getElementById("display_bar_p").innerHTML;
//creating numbers
if ((displayValue == 0) && (!displayValue.includes("."))) {
if (inputNumber == '.') {
displayValue = displayValue + inputNumber;
} else if (displayValue == '0.') {
displayValue = displayValue + inputNumber;
} else {
displayValue = inputNumber;
}
} else if (inputNumber == ".") {
if (!(displayValue.includes('.'))) {
displayValue = displayValue + "" + inputNumber;
}
} else {
displayValue = displayValue + "" + inputNumber;
}
updateAllDisplays(displayValue, smallDisplayValue);
//checking last character of small display and reseting the display
if (smallDisplayValue != "") {
var last_character = smallDisplayValue.slice(smallDisplayValue.length - 1);
if (last_character == "=") {
smallDisplayValue = "";
displayValue = inputNumber;
} else if (isNaN(last_character)) {
displayValue = inputNumber;
displayValue = inputNumber;
}
}
updateAllDisplays(displayValue, smallDisplayValue);
}
function doOperations(sign1) {
var last_character = smallDisplayValue.slice(smallDisplayValue.length - 1);
if (last_character == "=") {
smallDisplayValue = displayValue + sign1;
updateAllDisplays(displayValue, smallDisplayValue);
} else if (smallDisplayValue == "") {
smallDisplayValue = displayValue + sign1;
} else if (isNaN(smallDisplayValue)) {
doCalculation(sign1);
}
updateAllDisplays(displayValue, smallDisplayValue);
}
function clearDisplay() {
displayValue = 0;
smallDisplayValue = "";
updateAllDisplays(displayValue, smallDisplayValue);
}
function doCalculation(sign2) {
var outpute_value = eval(smallDisplayValue + displayValue);
if (sign2 == "=") {
smallDisplayValue += displayValue + "=";
displayValue = outpute_value;
} else if (sign2 != "=") {
smallDisplayValue = outpute_value + sign2;
displayValue = outpute_value;
}
updateAllDisplays(displayValue, smallDisplayValue);
}