Need help understanding the extra function calls in step 4 grade book app

I don’t know …There might be some sort of glitch in this step… After writing the function, the last line visible to me is (notice, there is only one call to studentMsg)-
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

While the output is -
//tests completed
// console output
Class average: 71.7. Your grade: F. You failed the course.
Class average: 71.7. Your grade: F. You failed the course.
Class average: 50.8. Your grade: A++. You passed the course.
Class average: 70.25. Your grade: A. You passed the course.

Where is the “undefined” coming from? Where are the other call functions coming from? There was only one call with the scores input. The other calls to studentMsg do not show up in the code.

Please creare your own topic to ask for help

HI @kichir !

Welcome to the forum!

I created a new topic for you. But in the future it is best to create your own topic :+1:

It is common in course curriculum to have extra test cases running against the code to ensure your code is behaving the way it is supposed to.

So while you see one test cases in the code, there are others running in the background too to ensure that the solutions are suing using truly reusable functions that can work for dozens of test cases.

Because sometimes with these challenges, people will try to hardcode their solution to only pass the test cases they see which defeats the purpose of creating the function in the first place

we would need to see your code for that.

Thank you for starting a new thread for me (and my apologies for not doing so on my own.)
I wasn’t sure if I could produce my code here. However, here is the code in its entirety that I could copy (Notice, there is only one call, with data, to the studentMsg function. However there are multiple outputs with data input from somewhere…) Thanks for your help in advance -

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

function studentMsg(totalScores, studentScore) {
  let baseMsg = "Class average: " + getAverage(totalScores) + ". Your grade: " + getGrade(studentScore) + ". ";
    console.log(baseMsg + "You passed the course.");
  } else {
    console.log(baseMsg + "You failed the course.");
studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37);

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

You are seeing undefined in the console because your function isn’t’ returning anything.

If you don’t explicitly return something then the default will be undefined .

hope that helps

there is one function call, that you can see.
But there are multiple function calls happening. It is happening when the tests are run.
that is to ensure that people are not returning hardcoded strings to fit one test case.
the correct answer should be a function that works for dozens of test cases.
It looks like you are on the right track with doing that.

But the mutliple function calls behind the scenes is to prevent people from doing something like this

function studentMsg(totalScores, studentScore) {
  return "Class average: 71.7. Your grade: F. You failed the course."

while that would pass one test, it would defeat the purpose of writing a function in the first place and it wouldn’t pass other test cases

Thank you for taking the time to look through the code and responding. I really appreciate it! While I know that my code works, its a bit frustrating that I can’t move beyond this stage and complete the level (there is an error message)! I just think its my OCD acting up and that it feels nice to complete a list!
My heartfelt thanks for sparing some of your time, being patient and going through the code!

1 Like

To pass, your function needs to return the message.

logging the message is helpful for debugging, but in the end you still need to return it :+1:

I think I figured out what the issue was!
Coding has many approaches to solve a given issue. The ‘compiler’ here seeks a particular way to solve the problem at hand. In this case, the compiler wants the user to generate a message in studentMsg such that it returns a string that can be then output by console.log (the last line in the code). After I altered that, I was eventually able to pass the stage!! Thank you so much again.

1 Like