-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputs.js
More file actions
42 lines (34 loc) · 1.14 KB
/
inputs.js
File metadata and controls
42 lines (34 loc) · 1.14 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
document.getElementById("clear").addEventListener("click", function () {
calculatorValue = "";
outputBox.value = "0";
});
document.getElementById("calculate").addEventListener("click", function () {
calculatorValue = outputBox.value;
try {
calculatorValue = parseExpression(calculatorValue).toString();
outputBox.value = calculatorValue;
} catch (e) {
alert("Division by zero is not allowed. Please fix your input value.");
}
});
document.getElementById("output-form").addEventListener("submit", function (event) {
event.preventDefault();
calculatorValue = outputBox.value;
try {
calculatorValue = parseExpression(calculatorValue).toString();
outputBox.value = calculatorValue;
} catch (e) {
alert("Division by zero is not allowed. Please fix your input value.");
}
});
outputBox.addEventListener("focusin", function () {
if (outputBox.value === "0") {
calculatorValue = "";
outputBox.value = calculatorValue;
}
});
outputBox.addEventListener("focusout", function () {
if (outputBox.value === "") {
outputBox.value = "0";
}
});