非常直截了当的问题我只对js是新手这是我的代码,如果它有助于理解我想要实现的目标
var highestMark=0;
var gradeAwarded;
var StudentArr= [Student];
var markArr = [mark];
var Student = prompt("Enter Student Name: ", "Name");
var mark = prompt("Enter Student Mark: ", 50);
var max = Math.max.apply(markArr); /* This about equal to Math.max(numbers[0], ...) or Math.max(5, 6, ..) */
var min = Math.min.apply(markArr);
if (mark < 0 || mark > 100) {
alert("Grate out of bounds");
} else if (mark >= 83) {
gradeAwarded = "A";
} else if (mark >= 70) {
gradeAwarded = "B";
} else if (mark >= 50) {
gradeAwarded = "C";
} else if (mark >= 0) {
gradeAwarded = "F";
}
document.write(min);
答案 0 :(得分:0)
另一种方式是使用Array.reduce
方法
var max = markArr.reduce(function(a,b){return Math.max(a,b)});
我不确定哪个更有效率。