Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Thử thách sổ điểm (Grade book) trong JavaScript

Viết hàm nhận 3 điểm số, tính trung bình và trả về xếp loại chữ theo thang: A (90-100), B (80-89), C (70-79), D (60-69), F (<60).

Ví dụ

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));

Kết quả

F C D