-
Notifications
You must be signed in to change notification settings - Fork 2
/
sTest.html
89 lines (89 loc) · 2.8 KB
/
sTest.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
<!DOCTYPE html>
<html>
<head>
<title>Simple Calculator</title>
<link rel="stylesheet" type="text/css" href="calc.css"></link>
<script type="text/javascript">
class Test{
run(){
console.log('run');
}
}
class Sub extends Test{
run(){
console.log('Sub');
}
}
const append = (number)=>{
const t = new Test();
const ss= new Sub();
t.run();
ss.run();
console.log(number);
let textbox = document.getElementById('text1');
textbox.value=textbox.value+number;
localStorage.setItem('number2',textbox.value);
}
const operate = (op)=>{
let textbox = document.getElementById('text1');
textbox.value='';
localStorage.setItem('operator',op);
let num1=localStorage.getItem('number2');
localStorage.setItem('number1',num1);
}
const calc = ()=>{
let first=parseInt(localStorage.getItem('number1'));
let second= parseInt(document.getElementById('text1').value);
let operator = localStorage.getItem('operator');
if(operator=='+')
document.getElementById('text1').value=parseInt(first+second);
if(operator=='-')
document.getElementById('text1').value=parseInt(first-second);
if(operator=='/')
document.getElementById('text1').value=parseInt(first/second);
if(operator=='*')
document.getElementById('text1').value=parseInt(first*second);
}
</script>
</head>
<body>
<div class="calculator-body">
<div class="screen">
<div class="input">
<span>Input</span>
<input type="text" name="" id="text1">
</div>
<div class="result"></div>
</div>
<div class="pad">
<div class="numpad">
<div class="row">
<input type="button" name="" value="1" onclick="append(1)">
<input type="button" name="" value="2" onclick="append(2)">
<input type="button" name="" value="3" onclick="append(3)">
</div>
<div class="row">
<input type="button" name="" value="4" onclick="append(4)">
<input type="button" name="" value="5" onclick="append(5)">
<input type="button" name="" value="6" onclick="append(6)">
</div>
<div class="row">
<input type="button" name="" value="7" onclick="append(7)">
<input type="button" name="" value="8" onclick="append(8)">
<input type="button" name="" value="9" onclick="append(9)">
</div>
<div class="row">
<input type="button" name="" value="0" onclick="append(0)">
<input type="button" name="" value="+" onclick="operate('+')">
<input type="button" name="" value="-" onclick="operate('-')">
</div>
<div class="row">
<input type="button" name="" value="/" onclick="operate('/')">
<input type="button" name="" value="*" onclick="operate('*')">
<input type="button" name="" value="=" onclick="calc()">
</div>
</div>
</div>
</div>
</body>
</html>