Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Tell us what’s happening:

i’m wondering if I must a passing or failing message for every student in this step. I mean the numbers in the log.

Your code so far

function getAverage(scores) {
  let sum = 0;

  for (const score of scores) {
    sum += score;
  }

  return sum / scores.length;
}

function getGrade(score) {
  if (score === 100) {
    return "A++";
  } else if (score >= 90) {
    return "A";
  } else if (score >= 80) {
    return "B";
  } else if (score >= 70) {
    return "C";
  } else if (score >= 60) {
    return "D";
  } else {
    return "F";
  }
}

function hasPassingGrade(score) {
  return getGrade(score) !== "F";
}


// User Editable Region

function studentMsg(totalScores, studentScore) {
if (hasPassingGrade)
}
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

// User Editable Region


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Hi there!

Complete the function by returning exact string given in the challenge instructions when checking condition within if statement.

I don’t really get what you mean because the passing message is hard because passing could mean every grade expect F

Instructions:
Complete the studentMsg function with totalScores and studentScore for parameters. The function should return a string representing a message to the student.

If the student passed the course, the string should follow this format:
Class average: average-goes-here. Your grade: grade-goes-here. You passed the course.

If the student failed the course, the string should follow this format:
Class average: average-goes-here. Your grade: grade-goes-here. You failed the course.

Use the getAverage function to get the class average.
Use the getGrade function to get the student’s grade.
Use string concatenation (+) to build the message.
Be careful with the punctuation and spaces in the message.

Now you need to use the format given in the instructions as returning string in if else statement. Read the instructions carefully and try again.

you are not answering my question. You just copy pasted the instruction in this step. I don’t know how to start because there are a lot of numbers which is confusing.

however, I have come this far. Please explain to me what I am missing.

function studentMsg(totalScores, studentScore) {
if (hasPassingGrade(totalScores)) {
return "Class average: 71.7. + Your grade: " + “You passed the course.”
} else {
return “Class average: 71.7. + Your grade: F” + “You failed the course.”
}
}
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

Tell us what’s happening:

why isn’t my second if working? I have tried adding else and if … else but it’s not working

Your code so far

function getAverage(scores) {
  let sum = 0;

  for (const score of scores) {
    sum += score;
  }

  return sum / scores.length;
}

function getGrade(score) {
  if (score === 100) {
    return "A++";
  } else if (score >= 90) {
    return "A";
  } else if (score >= 80) {
    return "B";
  } else if (score >= 70) {
    return "C";
  } else if (score >= 60) {
    return "D";
  } else {
    return "F";
  }
}

function hasPassingGrade(score) {
  return getGrade(score) !== "F";
}


// User Editable Region

function studentMsg(totalScores, studentScore) {
 if (hasPassingGrade(totalScores)) {
    return "Class average: 71.7. Your grade: . You passed the course."
  } else  { 
  return "Class average: 71.7. Your grade: F. You failed the course."
  }
 if (haspassingGrade(studentScore)) {
   return "Class average: 50.8. Your grade: A++ . You passed the course."
 }
}  
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

// User Editable Region


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 4

nvm…im wrong and its been a while

Hi @junser.2017

You have faded code in the editor, which means the code will never execute. Please remove it.

In the return statements you only have a string.

No matter what values are passed to the studentMsg function, the same message will get produced. What if the class average is not 71.7?

Happy coding

I went ahead and combined your posts for you. In the future, just reply to the original thread to add further updates.

Thanks.

1 Like

You are not using the function’s for average and garde. Instead you have added simple text 71.7 and F.
Concatenate the function’s getAverage() and getGrade() within the string for class average and student grade. Use the parameters totalScores and studentScore as an argument.

It’s still not letting me pass, but i’m not sure if i’m using the right functions.

function studentMsg(totalScores, studentScore) {
 if (hasPassingGrade(totalScores)) {
    return "getAverage(scores):" + "getGrade(score):" + "You passed the course."
  } else  { 
  return "getAverage(scores):" + "getGrade(score):" + "You failed the course."
  }
}  
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

It’s strange because I see some people using getAverage(totalScore) but there isn’t a function with that name. How come they just change the name of a function.

also, if the first function I created called.getAverage(scores) gives me the Class average score how come I can’t just use that function name to bring those numbers into a new function.

look at the functions. the getAverage() function have the calculation of average.
getGrade() function have the calculation of grade.
hasPasingGrade() function have the calculation of passing grade. if you call that funnctions in exact place with exact parmaters as an argument within the srings and concatenate it exactly it is needed, your challenge will pass.

you can not use the score as an argument. because you did not have score as a paramater within the function studentMsg(totalScores, studentScore) . you must use the paramters that you have within the function. also you have deleted some text in the beginning of your return strings.