-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.html
84 lines (82 loc) · 2.46 KB
/
calculator.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>
<title>Calculator</title>
<style>
button{
width:50px;
height:40px;
background-color:lightyellow;
border-radius:5px;
margin:2px;
font-size:21px;
}
#infield{
height:30px;
width:210px;
margin:3px 7px 3px 5px;
background-color:#f2efe6;
border-radius:5px;
font-size:21px;
}
table{
margin-top:50px;
background-color:skyblue;
border-radius:8px;
border-color:black;
}
</style>
</head>
<body>
<table align="center" width="200px" border="3">
<tr>
<td colspan="4"><input type="text" name="cal" id="infield"></td>
</tr>
<tr>
<td><button value="(" onClick="myfunction(this)">(</button></td>
<td><button value="ce" onClick="myfunction(this)">CE</button></td>
<td><button value=")" onClick="myfunction(this)">)</button></td>
<td><button value="c" onClick="myfunction(this)">C</button></td>
</tr>
<tr>
<td><button value="1" onClick="myfunction(this)">1</button></td>
<td><button value="2" onClick="myfunction(this)">2</button></td>
<td><button value="3" onClick="myfunction(this)">3</button></td>
<td><button value="+" onClick="myfunction(this)">+</button></td>
</tr>
<tr>
<td><button value="4" onClick="myfunction(this)">4</button></td>
<td><button value="5" onClick="myfunction(this)">5</button></td>
<td><button value="6" onClick="myfunction(this)">6</button></td>
<td><button value="-" onClick="myfunction(this)">-</button></td>
</tr>
<tr>
<td><button value="7" onClick="myfunction(this)">7</button></td>
<td><button value="8" onClick="myfunction(this)">8</button></td>
<td><button value="9" onClick="myfunction(this)">9</button></td>
<td><button value="*" onClick="myfunction(this)">*</button></td>
</tr>
<tr>
<td><button value="." onClick="myfunction(this)">.</button></td>
<td><button value="0" onClick="myfunction(this)">0</button></td>
<td><button value="=" onClick="myfunction(this)">=</button></td>
<td><button value="/" onClick="myfunction(this)">/</button></td>
</tr>
</table>
<script>
function myfunction(button){
var text=button.getAttribute("value");
var str=document.getElementById("infield").value;
if(text==="ce")
str=str.substring(0,str.length-1);
else if(text==="c")
str=" ";
else if(text==="=")
str=eval(str);
else
str=str+text;
document.getElementById("infield").value=str;
}
</script>
</body>
</html>