Im stuck on test 17.
here is the task -
- You should have a function named
getAveragethat takes an array of test scores as a parameter and returns the average score. - You should have a function named
getGradethat takes a student score as a parameter and returns a string representing a letter grade based on the score. Here are the scores and their corresponding letter grades:
| Score Range | Grade |
|---|---|
100 |
"A+" |
90 - 99 |
"A" |
80 - 89 |
"B" |
70 - 79 |
"C" |
60 - 69 |
"D" |
0 - 59 |
"F" |
- You should have a function named
hasPassingGradethat takes a score as a parameter and returns eithertrueorfalsedepending on if the score corresponds to a passing grade. - The
hasPassingGradefunction should use thegetGradefunction to get the letter grade, and use it to determine if the grade is passing. A passing grade is anything different from"F". - You should have a function named
studentMsgthat takes an array of scores and a student score as the parameters. The function should return a string with the format:
"Class average: average-goes-here. Your grade: grade-goes-here. You passed the course.", if the student passed the course."Class average: average-goes-here. Your grade: grade-goes-here. You failed the course.", if the student failed the course.Replaceaverage-goes-herewith the average of total scores andgrade-goes-herewith the student’s grade. UsegetAverageto get the average score andgetGradeto get the student’s grade.
tests -
-
- You should have a function named
getAverage.
- You should have a function named
-
Passed:2. Your
getAveragefunction should return a number. -
Passed:3.
getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89])should return71.7. -
Passed:4.
getAverage([45, 87, 98, 100, 86, 94, 67, 88, 94, 95])should return85.4. -
Passed:5.
getAverage([38, 99, 87, 100, 100, 100, 100, 100, 100, 100])should return92.4. -
Passed:6. Your
getAveragefunction should return the average score of the test scores. -
Passed:7. You should have a function named
getGrade. -
Passed:8. Your
getGradefunction should return"A+"if the score is100. -
Passed:9. Your
getGradefunction should return"A"if the score is between90and99. -
Passed:10. Your
getGradefunction should return"B"if the score is between80and89. -
Passed:11. Your
getGradefunction should return"C"if the score is between70and79. -
Passed:12. Your
getGradefunction should return"D"if the score is between60and69. -
Passed:13. Your
getGradefunction should return"F"if the score is between0and59. -
Passed:14. You should have a function named
hasPassingGrade. -
Passed:15. Your
hasPassingGradefunction should return a boolean value. -
Passed:16. Your
hasPassingGradefunction should returntrueif the grade is an"A". -
Failed:17. Your
hasPassingGradefunction should returnfalseif the grade is an"F". -
Passed:18. Your
hasPassingGradefunction should returntruefor all passing grades. -
Passed:19. You should have a function named
studentMsg. -
Passed:20.
studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37)should return the following message:"Class average: 71.7. Your grade: F. You failed the course.". -
Passed:21.
studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100)should return the following message:"Class average: 50.8. Your grade: A+. You passed the course.". -
Passed:22. Your
studentMsgfunction should return the correct message based on the student’s score and the class average.
const testArr = [92, 88, 12, 77, 57, 100, 67, 38, 97, 89],
testArr2 = [45, 87, 98, 100, 86, 94, 67, 88, 94, 95];
function getAverage(testArr) {
if (testArr.length > 0) {
let sum = 0;
for (let i = 0; i < testArr.length; i++) {
sum += testArr[i]
}
const average = sum / testArr.length;
return average;
}
}
function getGrade(testScore) {
if (testScore == 100){
return "A+";
} else if (testScore >= 90 && testScore <= 99) {
return "A";
} else if (testScore >= 80 && testScore <= 89) {
return "B";
} else if (testScore >= 70 && testScore <= 79) {
return "C";
} else if (testScore >= 60 && testScore <= 69) {
return "D";
} else if (testScore >= 0 && testScore <= 59){
return "F";
} else {
return `${testScore} is not a number`;
}
}
function hasPassingGrade(testScore) {
let failing = "F"
if (testScore !== failing) {
return true;
} else {
return false;
}
}
function studentMsg(testArr, studScore) {
let classAverage = getAverage(testArr),
studGrade = getGrade(studScore),
hasPassed = hasPassingGrade(studGrade);
if (hasPassed === true) {
return `Class average: ${classAverage}. Your grade: ${studGrade}. You passed the course.`;
} else {
return `Class average: ${classAverage}. Your grade: ${studGrade}. You failed the course.`;
}
}
console.log(studentMsg(testArr, 15));