Hi, guys. How are you doing? My body is very stiff because of tennis. Never mind. It was good exercise.
BTW, may I ask you something???
My mission is:
quote:
write a prgram that asks you how many numbers you have, asks you to enter them and works out the total of the numbers entered.
Here is my code:
code:
<html>
<head>
<script type="text/javascript">
function cal(){
var Num=parseInt(document.theForm.num.value);
var sum=parseInt(document.theForm.result.value);
for(i=1; i<=Num; i++){
ans=parseInt(prompt("Enter the number" + i));
sum = sum + ans;
}
return document.theForm.result.value=sum;
}
</script>
</head>
<body>
<h3>Mission:</h3>
<p>Write a program that asks you how myny numbers you have,<br /> asks you to enter them and
works out the total and the biggest of the numbers entered. </p>
<form name="theForm">
<p>How many numbers?
<input type="text" name="num" onBlur="cal()">
</p>
<p>The total value is:
<input type="text" name="result">
</p>
<input type="reset" value="Reset">
</form>
</body>
</html>
Loop seems to work fine, but in the total number box, it said Nan.
I don't know how to add up prompt box value. Would you know something about it???
Here is my uploaded file. Many many thanks in advance. Cheers.
Hiroki Kozai