Skip to content

Commit

Permalink
add avg function
Browse files Browse the repository at this point in the history
  • Loading branch information
sasbcl committed Sep 5, 2012
1 parent 3753e5a commit b372aa6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion calc.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<script language=javascript type="text/javascript">

var plus,minus,divide,multiply,max,pow,min
var plus,minus,divide,multiply,max,pow,min,avg

function initialize(){
plus=document.calc.operator.options[0]
Expand All @@ -14,6 +14,7 @@
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(){
Expand All @@ -33,6 +34,8 @@
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>
Expand All @@ -56,6 +59,7 @@ <h2>Calc</h2>
<option value=max>max
<option value=pow>**
<option value=min>min
<option value=avg>avg
</select>

<input type=text name=val2 size=10>
Expand Down

0 comments on commit b372aa6

Please sign in to comment.