Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Tell us what’s happening:

what’s the right code for this one? kinda stuck…

Your code so far

function studentMsg(totalScores, studentScore) {
if (hasPassingGrade(score)) {
message += ‘“Class average: ’ + (totalScores) + '.Your grade: ’ + (studentScore) + '. You passed the course.”’;
} else {
message += ‘“Class average: ’ + (totalScores) + '. Your grade: ’ + (studentScore) + '. You failed the course.”’;
}

return message;
}

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

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(score)) {
    message += '"Class average: ' + (totalScores) + '.Your grade: ' + (studentScore) + '. You passed the course."';
  } else {
    message += '"Class average: ' + (totalScores) + '. Your grade: ' + (studentScore) + '. You failed the course."';
  }
  
  return message;
} 

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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Hi @atumacvlxy

ReferenceError: score is not defined

You have a syntax error.

Resolve that first, then the error messages will guide you though the next steps.

Happy coding

really? the word score is already in the template i did not add that!

here’s the error: // running tests Your

studentMsg

function should return the correct message based on the student’s score and the class average. // tests completed // console output Class average: 71.7. Your grade: F. You failed the course.

My Code:

function studentMsg(totalScores, studentScore) {
const average = getAverage(totalScores);
  const grade = getGrade(studentScore);
  
  if (hasPassingGrade(studentScore)) {
    return `Class average: ${average.toFixed(1)}. Your grade: ${grade}. You passed the course.`;
  } else {
    return `Class average: ${average.toFixed(1)}. Your grade: ${grade}. You failed the course.`;
  }
}
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

here’s actually with the ‘+’ concatenation :

my code :

const average = getAverage(totalScores).toFixed(1);
  const grade = getGrade(studentScore);
  
  if (hasPassingGrade(studentScore)) {
    return "Class average: " + average + ". Your grade: " + grade + ". You passed the course.";
  } else {
    return "Class average: " + average + ". Your grade: " + grade + ". You failed the course.";
  }

task:

Step 4

Now that the teacher has all of the information they need, they want to be able to message the student with the results.

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.

Replace average-goes-here with the average of the total scores. Replace grade-goes-here with the student’s grade.

Tips

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

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 (').

1 Like

do not round, you were not asked to do that

1 Like

oh i see lmao thank you