Problem
- Create a function finalGrade, which calculates the final grade of a student depending on two parameters.
- 두 개의 매개변수에 따라 학생의 최종 점수를 계산한다.
- This function should return a number (final grade).
- There are four types of final grades:
- 100, if a grade for the exam is more than 90 or if a number of completed projects more than 10.
- exam이 90보다 크거나, 완료된 projects가 10보다 크다면, 100이다.
- 90, if a grade for the exam is more than 75 and if a number of completed projects is minimum 5.
- exam이 75보다 크고, 완료된 projects가 최소 5인 경우, 90이다.
- 75, if a grade for the exam is more than 50 and if a number of completed projects is minimum 2.
- exam이 50보다 크고, 완료된 projects가 최소 2인 경우, 75이다.
- 0, in other cases.
Solution 01
function finalGrade(exam, projects) {
if (exam > 90 || projects > 10) return 100;
if (exam > 75 || projects >= 5) return 90;
if (exam > 50 || projects >= 2) return 75;
return 0;
}
finalGrade(91, 0); // 100
finalGrade(0, 11); // 100
finalGrade(76, 5); // 90
finalGrade(75, 5); // 75
finalGrade(51, 2); // 75
finalGrade(50, 2); // 0
Solution 02
function finalGrade(exam, projects) {
if (exam > 90 || projects > 10) {
return 100;
} else if (exam > 75 && projects >= 5) {
return 90;
} else if (exam > 50 && projects >= 2) {
return 75;
} else {
return 0;
}
}
finalGrade(91, 0); // 100
finalGrade(0, 11); // 100
finalGrade(76, 5); // 90
finalGrade(75, 5); // 75
finalGrade(51, 2); // 75
finalGrade(50, 2); // 0
Solution 03
function finalGrade(exam, projects) {
return exam > 90 || projects > 10 ? 100 : exam > 75 && projects >= 5 ? 90 : exam > 50 && projects >= 2 ? 75 : 0;
}
finalGrade(91, 0); // 100
finalGrade(0, 11); // 100
finalGrade(76, 5); // 90
finalGrade(75, 5); // 75
finalGrade(51, 2); // 75
finalGrade(50, 2); // 0