代码:
const array = [80, 50, 80];
function something() {
let add = 0;
for (let sum of array)
add = add + sum;
let average = add / array.length;
console.log(average);
if (average < 71) return "F";
}
something();
输出:
70
请帮助我为什么return语句不返回F
答案 0 :(得分:2)
该函数返回该值,但是您不使用此值。
const array = [80, 50, 80];
function something() {
let add = 0;
for (let sum of array)
add = add + sum;
let average = add / array.length;
console.log(average);
if (average < 71) return "F";
}
console.log(something());