-
Notifications
You must be signed in to change notification settings - Fork 455
/
calc.html
75 lines (62 loc) · 1.78 KB
/
calc.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
<html>
<head>
<title>Calc</title>
<script language=javascript type="text/javascript">
var plus,minus,divide,multiply,max,pow,min,avg
function initialize(){
plus=document.calc.operator.options[0]
minus=document.calc.operator.options[1]
divide=document.calc.operator.options[2]
multiply=document.calc.operator.options[3]
max=document.calc.operator.options[4]
pow=document.calc.operator.options[5]
min=document.calc.operator.options[6]
avg=document.calc.operator.options[7]
}
function calculate(){
a = parseInt(document.calc.val1.value)
b = parseInt(document.calc.val2.value)
if (plus.selected)
document.calc.answer.value = a + b
if (minus.selected)
document.calc.answer.value = a - b
if (divide.selected)
document.calc.answer.value = a / b
if (multiply.selected)
document.calc.answer.value = a * b
if (max.selected)
document.calc.answer.value = Math.max(a,b)
if (pow.selected)
document.calc.answer.value = Math.pow(a,b)
if (min.selected)
document.calc.answer.value = Math.min(a,b)
if (avg.selected)
document.calc.answer.value = (a + b) / 2
}
</script>
</head>
<body onLoad="initialize()">
<h2>Calc</h2>
Enter a number in the first box and a number in the second box and select the answer button to see the answer.
<br>
Change the operation via the dropdown selection box if desired.
<form name="calc" action="post">
<input type=text name=val1 size=10>
<select name=operator>
<option value=plus>+
<option value=minus>-
<option value=divide>/
<option value=multiply>*
<option value=max>max
<option value=pow>**
<option value=min>min
<option value=avg>avg
</select>
<input type=text name=val2 size=10>
=
<input type=text name=answer size=10>
<input type=button value="show answer" onClick="calculate()">
</form>
<br><br>
</body>
</html>