-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiplicationDivision.html
More file actions
46 lines (41 loc) · 1.16 KB
/
Copy pathMultiplicationDivision.html
File metadata and controls
46 lines (41 loc) · 1.16 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
<DOCTYPE html>
<html>
<head>
<title>Online Calculator(Homework)</title>
</head>
<input type="text" name="Number1" id="num1">
<br>
<input type="text" name="Number2" id="num2">
<br>
<input type="button" name="eq" value="*" onclick="calculate('m')">
<input type="button" name="eq2" value="/" onclick="calculate('d')">
<input type="button" name="eq3" value="+" onclick="calculate('a')">
<input type="button" name="eq4" value="-" onclick="calculate('s')">
<p id="result"></p>
<script type="text/javascript">
function calculate(operation)
{
var num1 = document.getElementById('num1').value;
var num2 = document.getElementById('num2').value;
var myresult = "The answer is ";
if (operation == 'm') {
// Operation is Multiplication
myresult = myresult + num1 * num2 ;
}
else if (operation == 'd') {
// Operation is Division
myresult = myresult + num1/num2 ;
}
else if (operation == 'a') {
//Operation is Addition
var mysum = parseInt(num1) + parseInt(num2);
myresult = myresult + mysum;
}
else{
//Operation is Subtraction
myresult = myresult + (num1 - num2);
}
document.getElementById('result').innerHTML = myresult;
}
</script>
</html>