Need help with step 4 of gradebook app

I’ve been stuck in the same step. I watched a video on youtube (https://www.youtube.com/watch?v=63JkeDG4i4w&t=903s) in which he changed the number 37 at the end of the array ( console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37)); ) to 100 and it passed. Didn’t work for me.

Here’s my code:


function studentMsg(totalScores, studentScore) {
  if(hasPassingGrade(studentScore)) {
    return "Class average: " + getAverage(totalScores) + "." + "Your grade: " + getGrade(studentScore) + "." + "You passed the course."
  } else {
    return "Class average: " + getAverage(totalScores) + "." + "Your grade: " + getGrade(studentScore) + "." + "You failed the course."
  }
}

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

HI @rsca !

Welcome to the forum!

You don’t need to change the console statements to pass.

you are not passing because you have spacing issues in your return string.

Add this console statement, to the end of your function so you can compare the correct result with your result

function studentMsg(totalScores, studentScore) {
  if(hasPassingGrade(studentScore)) {
    return "Class average: " + getAverage(totalScores) + "." + "Your grade: " + getGrade(studentScore) + "." + "You passed the course."
  } else {
    return "Class average: " + getAverage(totalScores) + "." + "Your grade: " + getGrade(studentScore) + "." + "You failed the course."
  }
}

console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37))
;
console.log("Class average: 71.7. Your grade: F. You failed the course.")

hope that helps

1 Like

Thank you! I fixed the spacing and turns out there was one closing parenthesis missing! Sorry for that. I appreciate your attention :smile:

1 Like

hellow :wave:t4: :slightly_smiling_face:, I’m also a beginner here…

you can simplify your function as following,

let marks_arr =  [92, 88, 12, 77, 57, 100, 67, 38, 97, 89];
let std_mark = 37;

function studentMsg(totalScores, studentScore) {
  let status = (hasPassingGrade(studentScore)) ? "passed" : "failed";

  return `Class average:  ${getAverage(totalScores)} | Your grade: ${getGrade(studentScore)} | You ${status} the course`;
  }
}

console.log( studentMsg( marks_arr, std_mark ) );
;
  • wt I’ve done in the my return statement is identified as ‘Template Strings’ or ‘* String literal-ism *’.
  • in simple terms, if we use backticks ( ` ), instead of ordinary single-quotes ( ) or double-quotes ( " ) to start & end a string, we can avoid unnecessary spaces or missing spaces, multiple string concatenations etc…
  • but if we want our string to be dynamic, we can use curly-brackets { }, starting with a $ symbol to integrate any method invocations or variables, just as I’ve done above.
  • also you can use ternary operators to simplify a small-scale if-else condition ( with the help of a ternary operation, you can directly assign it’s return value to a variable. check the ‘status’ variable ).
  • by using this approach you will avoid unnecessary repetitions in your coding ( check your return statements, they are both alike ) & a clearly structured logic within your code.

Hello, I appreciate you taking the time to show a different solution to the problem. However, you’re using features that we haven’t learned yet, so it’s no helpful at the moment. Thanks, anyway! Glad to see you’re learning different ways of doing things. I think I’m still a little behind you in the learning process =)

1 Like