小编use*_*207的帖子

Javascript平均数组

这是我的第一篇文章.我正在编写一个程序来从四个输入框中获取输入,找出这四个输入框的总和并找到平均值.当我这样做时,我得到一个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] …
Run Code Online (Sandbox Code Playgroud)

javascript

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

javascript ×1