-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path25-binary-calc.html
84 lines (75 loc) · 2.03 KB
/
25-binary-calc.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Binary Calculator</title>
<style>
body {
width: 33%;
}
#res {
background-color: lightgray;
border: solid;
height: 48px;
font-size: 20px;
}
#btn0,
#btn1 {
background-color: lightgreen;
color: brown;
}
#btnClr,
#btnEql {
background-color: darkgreen;
color: white;
}
#btnSum,
#btnSub,
#btnMul,
#btnDiv {
background-color: black;
color: red;
}
.buttonClass {
width: 25%;
height: 36px;
font-size: 18px;
margin: 0px;
float: left;
}
</style>
</head>
<body>
<div id="res" class="resultClass"></div>
<div id="btns" class="buttonContainer">
<button id="btn0">0</button>
<button id="btn1">1</button>
<button id="btnClr">C</button>
<button id="btnEql">=</button>
<button id="btnSum">+</button>
<button id="btnSub">-</button>
<button id="btnMul">*</button>
<button id="btnDiv">/</button>
</div>
<script>
document.getElementById("btn0").addEventListener("click", () => {
document.getElementById("res").insertAdjacentHTML("beforeend", "0");
});
document.getElementById("btn1").addEventListener("click", () => {
document.getElementById("res").insertAdjacentHTML("beforeend", "1");
});
function operatorAction(eve) {
document
.getElementById("res")
.insertAdjacentHTML("beforeend", eve.target.innerHTML);
}
document.getElementById("btnSum").onclick = operatorAction;
document.getElementById("btnMul").onclick = operatorAction;
document.getElementById("btnDiv").onclick = operatorAction;
document.getElementById("btnSub").onclick = operatorAction;
document.getElementById("btnClr").onclick = () => {
document.getElementById("res").innerHTML = "";
};
</script>
</body>
</html>