<!doctype html>
这样?
function getGrade(score) {
if (score >= 80) return "HD(High Distinction)";
if (score < 80 & score >= 70) return "D(Distinction)";
if (score < 70 & score >= 60) return "C(Credit)";
if (score < 60 & score >= 50) "P(Pass)";
return "F(Failed)"
}
window.onload = function () {
var student, outputText, nLength, n, score, sLength, i, grade;
//all the student
student = ['Mary', 'Jim', 'Albert', 'Carroll', 'Francis', 'Michael', 'John', 'Tim', 'Carlos', 'Steven'];
score = [65, 70, 85, 90, 50, 62, 76, 88, 64, 45];
sLength = score.length;
outputText = "<table>";
outputText += "<tr>";
outputText += "<th>" + "Name" + "</th>";
outputText += "<th>" + "Score" + "</th>";
outputText += "<th>" + "Grade" + "</th>";
outputText += "</tr>";
for (i = 0, n = 0; i < sLength; i++, n++) {
outputText += "<tr>";
outputText += "<td>";
outputText += student[n];
outputText += "</td>";
outputText += "<td>" + score[i] + "</td>";
outputText += "<td>";
outputText += getGrade(score[i]);//////////
outputText += "</td>";
outputText += "</tr>";
}
outputText += "</table>";
document.getElementById("display").innerHTML = outputText;
}
showbo showbo if (score < 60 & score >= 50) "P(Pass)";这里少了个return。。。加上。if (score < 60 & score >= 50)return "P(Pass)"