Build a Gradebook App - Build a Gradebook App

Tell us what’s happening:

I am passing all the checks other than test 17. I am getting the correct result out of the function but for some reason unbeknownst to me, the function doesn’t pass.
Maybe a small typo or what can it be?!

Your code so far

// Get in the array and return the average of sum
function getAverage (array) {
  let result = 0;
  for(let num of array) {
    result += num;
  }
  return result / array.length;
}


// pass in the score and check what grade it is
function getGrade (int) {
  if(int === 100) {
    return "A+"
  } else if(int >= 90) {
    return "A"
  } else if (int >= 80) {
    return "B";
  } else if (int >= 70) {
    return "C";
  } else if(int >= 60) {
    return "D"
  } else {
    return "F"
  }
}

// Checks if getGrade function result is a passing grade
function hasPassingGrade (score) {
  return score !== "F" ? true : false;
}

// Show message to user if the grade is passable or not
function studentMsg (arrayScores, studentScore) {
  let averageScore = getAverage(arrayScores);
  let yourGrade = getGrade(studentScore);
  let passingGrade = hasPassingGrade(yourGrade);
  if(passingGrade) {
    return `Class average: ${averageScore}. Your grade: ${yourGrade}. You passed the course.`;
  } else {
    return `Class average: ${averageScore}. Your grade: ${yourGrade}. You failed the course.`;
  }

  
}
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 60));

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36

Challenge Information:

Build a Gradebook App - Build a Gradebook App

Summary

This text will be hidden

What is test 17? Which part of your code do you think meets the requirement?

Note - putting a space after a function name and before the ( ) for the argument list is pretty nonstandard for JS.

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

This one doesn’t pass the test, all the other are passing.

Please also answer my second question

The part where it returns true or false .

What part is that? Please quote or post just that function.

The result of hasPassingGrade(getGrade(59)) should return true or false, which it does, but the test doesn’t pass.

That is two functions. Which one is test 17 talking about?

As I said, function hasPassingGrade. hasPassingGrade function is taking as an argument the function getGrade which takes an integer as an argument.

Where does test 17 or the instructions say that? I don’t see it.

From the User Stories:

  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".

I don’t think that’s what that part means.

It looks like the score is supposed to be the parameter as a number not a grade as a string. You aren’t passing a number to hasPassingGrade.

Ok, so I misinterpreted the:

The hasPassingGrade function should use the getGrade function to get the letter grade

as to pass the getGrade function as a parameter which is not correct.

I corrected my code and it has now passed with flying colors :upside_down_face:
Thank you for pointing that out. Cheers :melting_face:

1 Like