-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjavascript-cal.html
74 lines (69 loc) · 4.21 KB
/
javascript-cal.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>calculator</title>
</head>
<body bgcolor="#f0ffff">
<h1 style="text-align: center">This my calculator</h1>
<hr size="20" color="black">
<div style="width: 261px; margin-left: 550px"; background="fff8dc">
<form name="calculator">
<input name="display" placeholder="0" style="width: 254px; height: 60px; text-align: right; font-size: 30; border-radius: 8px; margin: 3px">
<br>
<input type="button" value="7" onclick="document.calculator.display.value += '7'" style="width: 60px; height: 60px; font-size=30; border-radius=8px; margin: 3px">
<input type="button" value="8" onclick="document.calculator.display.value += '8'" style="width: 60px; height: 60px; font-size=30; border-radius=8px">
<input type="button" value="9" onclick="document.calculator.display.value += '9'" style="width: 60px; height: 60px; font-size=30; border-radius=8px">
<input type="button" value="+" onclick="btnplus()" style="width: 60px; height: 60px; font-size=30; border-radius=8px">
<br>
<input type="button" value="4" onclick="document.calculator.display.value +='4'" style="width: 60px; height: 60px; font-size=30; border-radius=8px; margin: 3px">
<input type="button" value="5" onclick="document.calculator.display.value += '5'" style="width: 60px; height: 60px; font-size=30; border-radius=8px">
<input type="button" value="6" onclick="document.calculator.display.value +='6'" style="width: 60px; height: 60px; font-size=30; border-radius=8px">
<input type="button" value="-" onclick="btnminus()" style="width: 60px; height: 60px; font-size=30; border-radius=8px">
<br>
<input type="button" value="1" onclick="document.calculator.display.value += '1'" style="width: 60px; height: 60px; font-size=30; border-radius=8px; margin: 3px">
<input type="button" value="2" onclick="document.calculator.display.value += '2'" style="width: 60px; height: 60px; font-size=30; border-radius=8px">
<input type="button" value="3" onclick="document.calculator.display.value += '3'" style="width: 60px; height: 60px; font-size=30; border-radius=8px">
<input type="button" value="*" onclick="btnmulti()" style="width: 60px; height: 60px; font-size=30; border-radius=8px">
<br>
<input type="button" value="0" onclick="document.calculator.display.value += '0'" style="width: 60px; height: 60px; font-size=30; border-radius=8px; margin: 3px">
<input type="button" value="%" onclick="btnMod()" style="width: 60px; height: 60px; font-size=30; border-radius=8px">
<input type="button" value="." onclick="btndot()" style="width: 60px; height: 60px; font-size=30; border-radius=8px">
<input type="button" value="/" onclick="btndiv()" style="width: 60px; height: 60px; font-size=30; border-radius=8px">
<br>
<input type="button" value="=" onclick="document.calculator.display.value = eval(document.calculator.display.value) " style="width: 124px; height: 60px; font-size: 30; border-radius: 8px; margin: 3px">
<input type="button" value="C" onclick="btnclear()" style="width: 124px; height: 60px; font-size: 30; border-radius: 8px">
</form>
</div>
<script>
function btnplus() {
document.calculator.display.value +="+";
document.calculator.display.style.textAlign ="right";
}
function btnminus() {
document.calculator.display.value +="-";
document.calculator.display.style.textAlign ="right";
}
function btnmulti() {
document.calculator.display.value +="*";
document.calculator.display.style.textAlign ="right";
}
function btnMod() {
document.calculator.display.value +="%";
document.calculator.display.style.textAlign ="right";
}
function btndot() {
document.calculator.display.value +=".";
document.calculator.display.style.textAlign ="right";
}
function btndiv() {
document.calculator.display.value +="/";
document.calculator.display.style.textAlign ="right";
}
function btnclear() {
document.calculator.display.value ="";
document.calculator.display.style.textAlign ="right";
}
</script>
</body>
</html>