forked from professional-git/calc2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc.html
71 lines (58 loc) · 1.67 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
<html>
<head>
<title>Advanced Calculator</title>
<script language=javascript type="text/javascript">
var plus,minus,divide,multiply,max,pow,min
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]
}
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)
}
</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=5>
<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
</select>
<input type=text name=val2 size=5>
=
<input type=text name=answer size=10>
<input type=button value="show answer" onClick="calculate()">
</form>
<br><br>
</body>
</html>