-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.html
More file actions
53 lines (44 loc) · 1.72 KB
/
Copy pathcalculator.html
File metadata and controls
53 lines (44 loc) · 1.72 KB
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
<html>
<head>
<script>
function add() {
var a = parseInt(document.getElementById('a').value);
var b = parseInt(document.getElementById('b').value);
r = a + b;
document.getElementById("result").innerHTML = a + " + " + b + " = " + r;
}
function sub() {
var a = parseInt(document.getElementById('a').value);
var b = parseInt(document.getElementById('b').value);
r = a - b;
document.getElementById("result").innerHTML = a + " - " + b + " = " + r;
}
function mul() {
var a = parseInt(document.getElementById('a').value);
var b = parseInt(document.getElementById('b').value);
r = a * b;
document.getElementById("result").innerHTML = a + " * " + b + " = " + r;
}
function div() {
var a = parseInt(document.getElementById('a').value);
var b = parseInt(document.getElementById('b').value);
r = a / b;
document.getElementById("result").innerHTML = a + " / " + b + " = " + r;
}
</script>
</head>
<body>
<h1>Calculator</h1>
<form>
Enter number 1:
<input type="text" id="a" /><br />
Enter number 2:
<input type="text" id="b" /><br />
<input type="button" value="Add" onClick="add()" />
<input type="button" value="Subtract" onClick="sub()" />
<input type="button" value="Multiply" onClick="mul()" />
<input type="button" value="Divide" onClick="div()" />
</form>
<p id="result"></p>
</body>
</html>