-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc.html
154 lines (137 loc) · 4.48 KB
/
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
#calc {
width: 300px;
height: 400px;
background: rgb(22, 22, 22);
border-radius: 10px;
box-shadow: 0 0 2px 4px #333;
padding-top: 2px;
}
.row {
width: 300px;
height: 50px;
margin: 5px 25px;
}
button {
width: 60px;
height: 50px;
margin-top: 0;
border-radius: 4px;
}
#screen {
width: 260px;
height: 60px;
margin: 10px 9px;
box-shadow: inset 0 0 2px 4px #222;
background: radial-gradient(rgb(54, 53, 53) 65%,#333 35%);
border: none;
padding-top: 10px;
padding-left: 20px;
margin-top: 30px;
font-size: 20px;
}
#switch {
width: 124px;
}
#clear {
width: 122px;
}
.row button {
border: none;
background: rgb(14, 13, 13);
color: #ddd;
box-shadow: 1px 1px 1px 1px #666;
}
.row:last-child {
margin-top: 3px;
}
.row button:active {
box-shadow: .5px .5px .5px .5px #333;
background: linear-gradient(to right bottom, #000, #333);
}
</style>
<title>Calculator</title>
</head>
<body>
<div id="calc">
<div id="screen"></div>
<div class="row">
<button onclick="SwitchMe(this)" id="switch">ON</button>
<button onclick="appendMe(this)" id="clear">A/C</button>
</div>
<div class="row">
<button onclick="appendMe(this)">1</button>
<button onclick="appendMe(this)">2</button>
<button onclick="appendMe(this)">3</button>
<button onclick="appendMe(this)">+</button>
</div>
<div class="row">
<button onclick="appendMe(this)">4</button>
<button onclick="appendMe(this)">5</button>
<button onclick="appendMe(this)">6</button>
<button onclick="appendMe(this)">*</button>
</div>
<div class="row">
<button onclick="appendMe(this)">7</button>
<button onclick="appendMe(this)">8</button>
<button onclick="appendMe(this)">9</button>
<button onclick="appendMe(this)">-</button>
</div>
<div class="row">
<button onclick="appendMe(this)">0</button>
<button onclick="appendMe(this)">.</button>
<button onclick="appendMe(this)">/</button>
<button onclick="appendMe(this)">=</button>
</div>
</div>
<script type="text/javascript">
var buttons=document.getElementsByTagName('button');
function appendMe(a) {
var result = document.getElementById('screen');
var k = a.innerHTML;
if(k == 'A/C') {
result.innerHTML = "0";
} else if(document.getElementById('switch').innerHTML == "ON") {
for(i=1; i<buttons[i]; i++) {
buttons[i].setAttribute("disabled", true);
}
}
else if(k == "=") {
result.innerHTML = eval(result.innerHTML);
}
else {
//If truely the screen value = 0
if(result.innerHTML == "0") {
result.innerHTML = k;
} else {
//meaning the screen value is something else,
result.innerHTML += k;
}
}
}
function SwitchMe(b) {
var result = document.getElementById('screen');
var k = b.innerHTML;
if(result.innerHTML !== "") {
result.innerHTML = "";
document.getElementById('switch').innerHTML = "ON";
for(i=1; i<buttons.length; i++ ) {
buttons[i].disabled = true;
}
}
else {
result.innerHTML = "0";
document.getElementById('switch').innerHTML = "OFF";
for(i=1; i<buttons.length; i++ ) {
buttons[i].disabled = false;
}
}
}
</script>
</body>
</html>