Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Tell us what’s happening:

Trying to code a student msg that shows avg , total scores and displays if you passed or failed. Here’s what I have so far.

const avg = getAverage(totalScores);
const grade = getGrade(studentScore);

let msg;
if (grade >= 60) {
    msg = `Class average: ${avg}. Your grade: ${grade}. You passed the course.`;
} else {
    msg = `Class average: ${avg}. Your grade: ${grade}. You failed the course.`;
}

return msg

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) {
  const average = getAverage(totalScores);
    const grade = getGrade(studentScore);
    
    let msg;
    if (grade >= 70) {
        msg = `Class average: ${average}. Your grade: ${grade}. You passed the course.`;
    } else {
        msg = `Class average: ${average}. Your grade: ${grade}. You failed the course.`;
    }
    
    return msg;

}
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/605.1.15 (KHTML, like Gecko) Version/16.6 Safari/605.1.15

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 4

The return msg should not be there if needed at all. Good luck

SyntaxError: Illegal return statement

Take a close look at the test you are failing

here is the error message

Your function call of studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100) should return the following message: "Class average: 50.8. Your grade: A++. You passed the course." .

now, look at what your code produces

Class average: 50.8. Your grade: A++. You failed the course.

if the student received a grade of A++ why does your message say they failed the course?
they should only fail if their grade was an F

Take a close look at your logic here because that is where the issue is

what is grade?
hint: it is not a number

add this console statement after your code to see what grade actually it and which data type you are actually working with

function studentMsg(totalScores, studentScore) {
  const average = getAverage(totalScores);
    const grade = getGrade(studentScore);
    
    let msg;
    if (grade >= 70) {
        msg = `Class average: ${average}. Your grade: ${grade}. You passed the course.`;
    } else {
        msg = `Class average: ${average}. Your grade: ${grade}. You failed the course.`;
    }
    
    return msg;

}
console.log("this is grade", getGrade(100))

once you fix your if statement, then the test will pass

hope that helps

@Jay718
I think the issue is with the condition if((grade) > = 60){..}
Remember for this case, ‘F’ is failed and the rest passed. so it’s where we should base for the condition.
Here is what i have tried out
solution removed by moderator

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.