Jeff
04-07-2008, 01:02 AM
I am trying to create a function to take the average of a set of numbers that the user enters. I am not having much luck
<html>
<head>
<script language="JavaScript" type="text/javascript">
function getAvg(howmany) {
for (i=0;i<howmany;i++) {
var num = prompt("Please enter the number", "")
var total += num
var avg = total / howmany
}
return(avg)
}
</script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
var amount = prompt("Please enter the amount of numbers you wish to average", "")
getAvg(amount)
</script>
</body>
</html>
<html>
<head>
<script language="JavaScript" type="text/javascript">
function getAvg(howmany) {
for (i=0;i<howmany;i++) {
var num = prompt("Please enter the number", "")
var total += num
var avg = total / howmany
}
return(avg)
}
</script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
var amount = prompt("Please enter the amount of numbers you wish to average", "")
getAvg(amount)
</script>
</body>
</html>