成绩册挑战 JavaScript
javascriptweb developmentfront end technologyobject oriented programming
我们需要编写一个函数,找到传递给它的三个分数的平均值,并根据下表返回与该成绩相关的字母值。
示例
const findGrade = (...scores) => { const { length } = scores; const sum = scores.reduce((acc, val) => acc + val); const score = sum / length; if (score >= 90 && score <= 100) { return 'A'; } else if (score >= 80 ) { return 'B'; } else if (score >= 70 ) { return 'C'; } else if (score >= 60) { return 'D'; } else{ return 'F'; }; } console.log(findGrade(5,40,93)); console.log(findGrade(30,85,96)); console.log(findGrade(92,70,40));
输出
控制台中的输出将是 −
F C D