Instructions:
Create a function finalGrade, which calculates the final grade of a student depending on two parameters: a grade for the exam and a number of completed projects.
This function should take two arguments: exam - grade for exam (from 0 to 100); projects - number of completed projects (from 0 and above);
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.
90, if a grade for the exam is more than 75 and if a number of completed projects is minimum 5.
75, if a grade for the exam is more than 50 and if a number of completed projects is minimum 2.
0, in other cases
Examples(Inputs-->Output):
100, 12 --> 100
99, 0 --> 100
10, 15 --> 100
85, 5 --> 90
55, 3 --> 75
55, 0 --> 0
20, 2 --> 0
Thoughts:
1.I use the if/else statement to determine the return of the final grade function of different conditions.
2.Inside the if/else statement I use short circuit || and && based on the requirements from the instructions.
Solution:
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;
}
Top comments (3)
When looking at a student’s final grade, it’s important to understand that it’s usually a combination of exams, coursework, and class participation. For parents and students in Singapore, the official posting results for secondary school process provides the final outcome after all assessments are considered.
Key points:
Exams: Typically make up the largest portion of the final grade.
Coursework / Continuous Assessment: Projects, assignments, and class participation also contribute.
Weightage: Different subjects may have different weightings between exams and coursework.
Posting Results for Secondary School: Once results are finalized, the posting process determines school placements for the next level, so understanding grades is crucial for planning ahead.
In short, a student’s final grade is not just a number — it reflects overall performance and impacts the posting results for secondary school, which is an important step in a student’s academic journey.
Love how you broke down the logic before coding. Did you mean to use single '&' or was it supposed to be '&&' for logical AND?
Thanks so much! I'm glad you liked the breakdown. Great catch—yes, I actually meant to use && for logical AND. Appreciate you pointing that out! 🙌