これは私の最初の投稿です。4 つの入力ボックスから入力を取得し、これら 4 つの合計を求めて平均を求めるプログラムを作成しています。そうすると、NaNエラーが発生します。誰かが間違っている場所を指摘できますか。ありがとう
<html>
<head>
<title> Average marks </title>
<script type = "text/javascript">
function average(form)
{
scores = new Array(4)
scores [0] = form.mark1.value
scores [0] = new Number(scores[0])
scores [1] = form.mark2.value
scores [1] = new Number(scores[1])
scores [2] = form.mark3.value
scores [2] = new Number(scores[2])
scores [3] = form.mark4.value
scores [3] = new Number(scores[3])
var Sum = 0
var average
for(var x = 0; x < scores.length; x ++)
{
Sum = Sum + scores[x]
average = Sum / scores[x]
}
document.write("The sum of the marks is equal to " + Sum + "<br>")
document.write("The average of these marks is equal to " + average + "<br>")
}
</script>
</head>
<body>
<form>
Enter the first mark : <input type = "text" name="mark1"> <br>
Enter the second mark : <input type = "text" name="mark2"> <br>
Enter the third mark : <input type = "text" name="mark3"> <br>
Enter the fourth mark : <input type = "text" name="mark4"> <br>
<input type = "submit" value = "submit" onclick="average(this.form)">
</form>
</body>
</html>