Build a Gradebook App

Hi

function getAverage(scores) {

  let total = 0;
  for(const score of scores) {
    total += score
  }

  return total / scores.length;
}

function getGrade(score) {

  let grade = "";

  if (score === 100) {
    grade = "A+";
  } else if (score >= 90 && score <= 99) {
    grade = "A";
  } else if (score >= 80 && score <= 89) {
    grade = "B";
  } else if (score >= 70 && score <= 79) {
    grade = "C";
  } else if (score >= 60 && score <= 69) {
    grade = "D";
  } else {
    grade = "F";
  }

  return grade;
}

function hasPassingGrade(grade) {

  console.log(grade)
  if (grade === "F") {
    
    return false;

  } else {

    return true;
  }

}

function studentMsg(scores, studentScore) {

  const classAverage = getAverage(scores);
  const grade = getGrade(studentScore);

  if (hasPassingGrade(grade)) {
    return "Class average: " + classAverage + ". Your grade: " + grade + ". You passed the course."
  } else {
    return "Class average: " + classAverage + ". Your grade: " + grade + ". You failed the course."    
  }
  

}

console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

It’s not passing a single test:

19. Your hasPassingGrade function should return false if the grade is an "F".

Could it be a bug on your side or am I missing something here.

What do the instructions say about the parameters of hasPassingGrade?

1 Like
  1. You should have a function named hasPassingGrade that takes a score as a parameter and returns either true or false depending on if the score corresponds to a passing grade.

  2. The hasPassingGrade function should use the getGrade function to get the letter grade, and use it to determine if the grade is passing. A passing grade is anything different from "F".

Are you doing what it says in instruction 3?

1 Like

Yes it seems I might be missing the other point 4.

I updated the function hasPassingGrade below.

removed by moderator

I also changed

removed by moderator

Everything seems to be passing now. Thank you .

Congratulations on solving the challenge! You should be proud of your achievement…we are! But we are removing your working solution, so it is not available to others who have not yet done the work to get there. Again, congrats!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.