当我运行该程序时,浏览器告诉我moy是NaN但我注意使用.map(Number)将数组转换为数字。我需要一些帮助。
var score = [];
var i = 0;
var choice = 0;
while(choice != null){
i++;
score.push(prompt("put the score number "+i));
score = score.map(Number);
choice = prompt("to continue click on ok to cancel click on cancel");
}
var sum = 0,moy;
for(a=0;a<=i;a++) {
sum = sum+score[a];
moy = sum/i;
}
document.write("you put "+i+" score(s) <br>and the average is"+moy);
&#13;
答案 0 :(得分:0)
此行中存在语法错误
Slope = function(x) {
TempDF = data.frame(x, year=1:ncol(data))
lm(x ~ year, data=TempDF)$coefficients[2]
}
TData = as.data.frame(t(data))
data$slope = sapply(TData, Slope)
data
Year1 Year2 Year3 Year4 slope
1 4 0 5 18 4.7
2 2 10 6 4 0.2
定义一个像这样的变量
for(a=0;a<=i;a++) {