-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
executable file
·96 lines (90 loc) · 2.2 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var theorange = "color:rgb(255,145,0);background:#1a1a1a;font-size:xx-large";
var thegrey = "color:white;background:#1a1a1a;font-size:xx-large";
console.log(
"%cS%cantosh %cP%candey %c©2020.",
theorange,
thegrey,
theorange,
thegrey,
thegrey
);
var a = document.getElementById("op1");
var b = document.getElementById("op2");
var r = document.getElementById("res");
window.onload = () => {
clearit = () => {
a.value = "";
b.value = "";
r.value = "";
};
emptyCheck = () => {
if (a.value == "" || b.value == "") {
return true;
} else {
return false;
}
};
add = () => {
if (emptyCheck()) {
clearit();
alert("Enter the numbers and then continue.");
} else {
var c = Number(a.value) + Number(b.value);
var re = /^[-+]?[0-9]+\.[0-9]+$/;
if (!String(c).match(re)) c = parseInt(c);
else {
c = parseFloat(c);
c = c.toFixed(3);
}
r.value = c;
}
};
minus = () => {
if (emptyCheck()) {
clearit();
alert("Enter the numbers and then continue.");
} else {
var c = Number(a.value) - Number(b.value);
var re = /^[-+]?[0-9]+\.[0-9]+$/;
if (!String(c).match(re)) c = parseInt(c);
else {
c = parseFloat(c);
c = c.toFixed(3);
}
r.value = c;
}
};
multiply = () => {
if (emptyCheck()) {
clearit();
alert("Enter the numbers and then continue.");
} else {
var c = Number(a.value) * Number(b.value);
var re = /^[-+]?[0-9]+\.[0-9]+$/;
if (!String(c).match(re)) c = parseInt(c);
else {
c = parseFloat(c);
c = c.toFixed(3);
}
r.value = c;
}
};
divide = () => {
if (emptyCheck()) {
clearit();
alert("Enter the numbers and then continue.");
} else {
var c = Number(a.value) / Number(b.value);
var re = /^[-+]?[0-9]+\.[0-9]+$/;
if (!String(c).match(re)) c = parseInt(c);
else {
c = parseFloat(c);
c = c.toFixed(3);
}
if (c == Infinity || c == NaN) {
c = "undefined";
}
r.value = c;
}
};
};