-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimplecalc.js
More file actions
48 lines (43 loc) · 1.19 KB
/
Copy pathsimplecalc.js
File metadata and controls
48 lines (43 loc) · 1.19 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
var numberdigbuttons = document.querySelectorAll(".dig").length;
var arr = [];
for (var i=0 ; i < numberdigbuttons ; i++)
{
document.querySelectorAll(".dig")[i].addEventListener("click",function(){
var x = this.innerHTML;
var ax = parseInt(x);
document.getElementById("disp1").value +=ax;
}
)}
for (var q=0 ; q < numberdigbuttons ; q++)
{
document.querySelectorAll(".dig1")[q].addEventListener("click",function(){
var y = this.innerHTML;
var ay = parseInt(y);
document.getElementById("disp2").value +=ay;
}
)}
function math (op)
{
var xx = 0;
var yy = 0;
var x = document.getElementById("disp1").value;
var xx = parseInt(x);
var y = document.getElementById("disp2").value;
var yy = parseInt(y);
var result;
switch (op) {
case 'add':
result = xx + yy;
break;
case 'minus':
result = xx - yy;
break;
case 'mul':
result = xx * yy;
break;
case 'divi':
result = xx / yy;
break;
}
document.getElementById("resu").innerHTML = "the result is " + result;
}