Build a Gradebook App - Build a Gradebook App

Tell us what’s happening:

I’ve tried a few different ways but can’t seem to get my hasPassingGrade function to work properly

  1. You should have a function named hasPassingGrade.
    Failed:17. Your hasPassingGrade function should return a boolean value.
    Failed:18. Your hasPassingGrade function should return true if the grade is an “A”.
    Failed:19. Your hasPassingGrade function should return false if the grade is an “F”.
    Failed:20. Your hasPassingGrade function should return true for all passing grades.

Your code so far

function getAverage(arr) { 
  let total = 0; 
  for (const number of arr) { 
    total += number; 
    } return total / arr.length; 
} 
  function getGrade(score) 
  { if(score === 100) { 
  return 'A+'
  } else if(score <= 99 && score >= 90){ 
  return 'A' 
  } else if(score <= 89 && score >= 80) { 
  return 'B' 
  } else if(score <= 79 && score >= 70) { 
  return 'C' 
  } else if(score <= 69 && score >= 60) { 
  return 'D'
} else return 'F' 
} 
function hasPassingGrade(getGrade) { 
  if(getGrade !== 'F') {
    return true
  } else {
    return false
  } 
 } 
 
    function studentMsg(totalScores, studentScore) { 
      if (hasPassingGrade = true) { 
      return "Class average: " + getAverage(totalScores) + ". Your grade: " + getGrade(studentScore) + ". You passed the course."; 
      } else if(hasPassingGrade = false) {
        return "Class average: " + getAverage(totalScores) + ". Your grade: " + getGrade(studentScore) + ". You failed the course."; } }

console.log(getGrade(80))
console.log(getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89]));
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37))
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36

Challenge Information:

Build a Gradebook App - Build a Gradebook App

Please delete or comment out the last console.log() lines from your code.
Sometimes console.log() can disturb the tests.

You will see much less failed test. Giving you hint to the solution.

Please write if it still doesn´t leading you to the answer.

  1. You should have a function named hasPassingGrade that takes a score as a parameter

Please review the user stories carefully and make sure each one is implemented correctly.

I got rid of the console logs and it did fix things. My hasPassingGrade only seems to return false even when I tried to change it though. That seems to be the last thing I’m stuck on

Failed:18. Your hasPassingGrade function should return true if the grade is an "A".

Passed:19. Your hasPassingGrade function should return false if the grade is an "F".
Failed:20. Your hasPassingGrade function should return true for all passing grades.

Other than the consolge.log() removing, did you made anything else? If yes, pelase share the updated code.

function hasPassingGrade(score) {
const passingGrades = [(‘A’, ‘B’, ‘C’, ‘D’)]
if(score !== passingGrades) {
return false
} else if(score === passingGrades) {
return true
}
}

This is the only other change I had made

User Story #4 says, " The hasPassingGrade function should use the getGrade function to get the letter grade." Are you doing that?

Would I need to use a nested function for that? I haven’t done that part if so

You just need to call getGrade() inside hasPassingGrade(). Notice that the score parameter passed to getGrade() is also passed to hasPassingGrade().

If you learning in order, you probably learned that part of the curriculum:

What Are Closures, and How Do They Work?

Where you can see function inside of another function.
If you mean

that way.

Don’t worry about the tests until you’ve implemented the User Stories.

Please review the user stories carefully and make sure each one is implemented correctly.

  1. The hasPassingGrade function should use the getGrade function

I got the outcome I want for all but now with

function hasPassingGrade(score) {
const grade = getGrade(score);
return grade !== ‘F’;
}

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

This is the only one left so I just have to find out why F isn’t equaling false. I tried inputting an “if” statement to resolve it but it only made more tests fail

Understood. It would be this then right?

function hasPassingGrade(score) {
const grade = getGrade(score);
if(grade !== ‘F’){
return true;
}
}

Your code for hasPassingGrade() was correct in your last reply to me. The issue is now with your studentMsg() function.

Do you see it?

I apologize, I don’t see it. Am I calling the wrong function to studentMsg?

No need to apologize.

Look at the operator you are using in your condition. What is that operator used for? What operator should be used instead to test for equality? But since hasPassingGrade returns a boolean, do you even need an operator?

The operator I used is for strict equals so I can see how that can be an issue. would it still be an if statement without a condition?

The operator you used is to assign a value to a variable. The operator you need to use, if you use an operator at all, would be to test for equality. Do you remember what that is?

use console.log to test the result of your condition and test it with different input.

Something like this:

console.log(studentScore, hasPassingGrade,hasPassingGrade = true) 
if (hasPassingGrade = true) { 

This way you can see how different input is going to be evaluated by your if statement. Reduce any mysteries by using console.log() to see the operation of your program.

Also, what is hasPassingGrade? Is that a variable?

if you write if(true), that is a valid if statement.

1 Like