求高手搭救---代码实现不了
求平均值的时候,平均值avg的值现在为不是数字,当输出放在函数外面的时候,avg的值显示找不到,请各位高手帮小弟看看这段代码那里出现错误<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<script>
function student(id,name,grades)
{
this.id = id
this.name = name
this.grades = grades
}
student.prototype.average = function(){
var sum = 0
for ( i=0;i< this.grades.length;i++ )
{
sum+=this.grades[i];
}
var avg = sum/this.grades.length;
document.write("avg;"+avg+"<br>"+"id;"+s1.id+"<br>"+"name;"+s1.name+"<br>"+"gardes;"+s1.grades)
}
var s1 = new student(008,"das",[1654,4654,4654,])
s1.average();
//with(document)
//{
//write("id:"+s1.id+"<br>")
//write("name:"+s1.name+"<br>")
//rite("gardes:"+s1.grades+"<br>")
//write("avg:"+s1.avg+"<br>")
//}
</script>
</body>
</html>
[[it] 本帖最后由 zcmxjp 于 2008-11-12 15:12 编辑 [/it]]