-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
340 lines (265 loc) · 9.47 KB
/
index.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Kauhasen laskin</title>
</head>
<body>
<!-- Display elements: rect as the output display, root as the number panel container-->
<!--div id = "rect"></div-->
<div id = "rect"></div>
<div id="root"></div>
<!-- react, react-dom and in-browser babel interpreter-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.21.1/babel.min.js"></script>
<!-- first script: creating the number panel && math operations-->
<script type="text/babel">
class NumberPanel extends React.Component {
render() {
//strings for collecting the input data
let str1 = '';
let str2 = '';
let activeStr = "str_1";
let buttonWidth = 80;
let buttonHeight = 80;
let minusButtonPushed;
let plusButtonPushed;
let timesButtonPushed;
let dividerButtonPushed;
let equButtonPushed;
function updateDisp(input){
let ta = document.getElementById("outputtext");
ta.innerHTML = input;
}
function c1(){
if(activeStr == "str_1"){
str1 +='1';
updateDisp(str1);
}
else{
str2+= '1';
updateDisp(str2);
}
}
function c2(){
if(activeStr == "str_1"){
str1 +='2';
updateDisp(str1);
}
else{
str2+= '2';
updateDisp(str2);
}
}
function c3(){
if(activeStr == "str_1"){
str1 +='3';
updateDisp(str1);
}
else{
str2+= '3';
updateDisp(str2);
}
}
function c4(){
if(activeStr == "str_1"){
str1 +='4';
updateDisp(str1);
}
else{
str2+= '4';
updateDisp(str2);
}
}
function c5(){
if(activeStr == "str_1"){
str1 +='5';
updateDisp(str1);
}
else{
str2+= '5';
updateDisp(str2);
}
}
function c6(){
if(activeStr == "str_1"){
str1 +='6';
updateDisp(str1);
}
else{
str2+= '6';
updateDisp(str2);
}
}
function c7(){
if(activeStr == "str_1"){
str1 +='7';
updateDisp(str1);
}
else{
str2+= '7';
updateDisp(str2);
}
}
function c8(){
if(activeStr == "str_1"){
str1 +='8';
updateDisp(str1);
}
else{
str2+= '8';
updateDisp(str2);
}
}
function c9(){
if(activeStr == "str_1"){
str1 +='9';
updateDisp(str1);
}
else{
str2+= '9';
updateDisp(str2);
}
}
function c0(){
if(activeStr == "str_1"){
str1 +='0';
updateDisp(str1);
}
else{
str2+= '0';
updateDisp(str2);
}
}
function CE(){
updateDisp(0);
}
function ClearOutput(){
str1 = '';
str2 = '';
activeStr = "str_1";
}
function equals(){
let int_1 = parseInt(str1);
let int_2 = parseInt(str2);
let res = 0;
if(minusButtonPushed){
res = int_1 - int_2;
updateDisp(res);
str1 = '';
str2 = '';
minusButtonPushed = 0;
ClearOutput();
}
if(plusButtonPushed){
res = int_1 + int_2;
updateDisp(res);
str1 = '';
str2 = '';
plusButtonPushed = 0;
ClearOutput();
}
if(timesButtonPushed){
res = int_1 * int_2;
updateDisp(res);
str1 = '';
str2 = '';
timesButtonPushed = 0;
ClearOutput();
}
if(dividerButtonPushed){
if(int_2 === 0){
alert("Ei kovin mielellään");
ClearOutput();
updateDisp("Math error");
return;
}
else{
res = int_1 / int_2;
updateDisp(res);
str1 = '';
str2 = '';
}
dividerButtonPushed = 0;
ClearOutput();
}
}
function plus(){
plusButtonPushed = 1;
minusButtonPushed = 0;
timesButtonPushed = 0;
dividerButtonPushed = 0;
activeStr = "str2";
}
function minus(){
plusButtonPushed = 0;
minusButtonPushed = 1;
timesButtonPushed = 0;
dividerButtonPushed = 0;
activeStr = "str2";
}
function times(){
plusButtonPushed = 0;
minusButtonPushed = 0;
timesButtonPushed = 1;
dividerButtonPushed = 0;
activeStr = "str2";
}
function divide(){
plusButtonPushed = 0;
minusButtonPushed = 0;
timesButtonPushed = 0;
dividerButtonPushed = 1;
activeStr = "str2";
}
return (
<div>
{/* buttons 7-9 */}
<button onClick={c7} style={{height: buttonHeight, width: buttonWidth, borderRadius: '4px', fontWeight: 'bold', backgroundColor: 'silver'}}>7</button>
<button onClick={c8} style={{height: buttonHeight, width: buttonHeight, borderRadius: '4px', fontWeight: 'bold', backgroundColor: 'silver'}}>8</button>
<button onClick={c9} style={{height: buttonHeight, width: buttonHeight, borderRadius: '4px', fontWeight: 'bold', backgroundColor: 'silver'}}>9</button>
<button onClick = {CE} style={{height: buttonHeight, width: buttonHeight, borderRadius: '4px', fontWeight: 'bold', backgroundColor: 'silver'}}>CE</button><br/>
{/* buttons 4-6 */}
<button onClick={c4} style={{height: buttonHeight, width: buttonHeight, borderRadius: '4px', fontWeight: 'bold', backgroundColor: 'silver'}}>4</button>
<button onClick={c5} style={{height: buttonHeight, width: buttonHeight, borderRadius: '4px', fontWeight: 'bold', backgroundColor: 'silver'}}>5</button>
<button onClick={c6} style={{height: buttonHeight, width: buttonHeight, borderRadius: '4px', fontWeight: 'bold', backgroundColor: 'silver'}}>6</button>
<button onClick={plus} style={{height: buttonHeight, width: buttonHeight, borderRadius: '4px', fontWeight: 'bold', backgroundColor: 'silver'}}>+</button><br/>
{/* buttons 1-3 */}
<button onClick={c1} style={{height: buttonHeight, width: buttonHeight, borderRadius: '4px', fontWeight: 'bold', backgroundColor: 'silver'}}>1</button>
<button onClick={c2} style={{height: buttonHeight, width: buttonHeight, borderRadius: '4px', fontWeight: 'bold', backgroundColor: 'silver'}}>2</button>
<button onClick={c3} style={{height: buttonHeight, width: buttonHeight, borderRadius: '4px', fontWeight: 'bold', backgroundColor: 'silver'}}>3</button>
<button onClick={minus} style={{height: buttonHeight, width: buttonHeight, borderRadius: '4px', fontWeight: 1200, backgroundColor: 'silver'}}>-</button><br/>
{/* buttons *, 0, / */}
<button onClick={times} style={{height: buttonHeight, width: buttonHeight, borderRadius: '4px', fontWeight: 'bold', backgroundColor: 'silver'}}>*</button>
<button onClick={c0} style={{height: buttonHeight, width: buttonHeight, borderRadius: '4px', fontWeight: 'bold', backgroundColor: 'silver'}}>0</button>
<button onClick={divide} style={{height: buttonHeight, width: buttonHeight, borderRadius: '4px', fontWeight: 'bold', backgroundColor: 'silver'}}>/</button>
<button onClick = {equals} style={{height: buttonHeight, width: buttonHeight, borderRadius: '4px', fontWeight: 'bold', backgroundColor: 'silver'}}>=</button><br/>
<p>{str1}</p>
</div>
);
}
}
ReactDOM.render(
<NumberPanel />,document.getElementById('root')
);
</script>
<!-- Second script: creating the display rectangle -->
<script type="text/babel">
class DisplayRectangle extends React.Component{
render(){
return(
<div>
<svg width="340" height="110">
<rect id ="output" width="320" height="110" style={{fill: 'blue', border: '2px'}}>
</rect>
<text id = "outputtext" x="20" y="90" fontFamily="Arial" fontSize="30" fill="white" ></text>
</svg>
</div>
);
}
}
ReactDOM.render(<DisplayRectangle/>, document.getElementById('rect'));
</script>
</body>
</html>