-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
47 lines (45 loc) · 996 Bytes
/
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
var ans = "";
var clear = false;
var calc = "";
$(document).ready(function() {
$("button").click(function() {
var text = $(this).attr("value");
if (
text === "1" ||
text === "2" ||
text === "3" ||
text === "4" ||
text === "5" ||
text === "6" ||
text === "7" ||
text === "8" ||
text === "9" ||
text === "0" ||
text === "." ||
text === "/" ||
text === "*" ||
text === "-" ||
text === "+" ||
text === "%"
) {
if (clear === false) {
calc += text;
$(".textbox").val(calc);
} else {
calc = text;
$(".textbox").val(calc);
clear = false;
}
} else if (text === "AC") {
calc = "";
$(".textbox").val("");
} else if (text === "CE") {
calc = calc.slice(0, -1);
$(".textbox").val(calc);
} else if (text === "=") {
ans = eval(calc);
$(".textbox").val(ans);
clear = true;
}
});
});