Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Tell us what’s happening:

Hi there

I’m in need for some help please? I don’t know what I am missing, can someone please help

thanks alot
Iskren

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 (grade==="F"){
    return "Class average:"+ getAverage(); + "Your grade:" + getGrade(); + "You failed the course".
  } else {
    return "Class average:"+ getAverage(); + "Your grade:" + getGrade(); + "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/605.1.15 (KHTML, like Gecko) Version/17.4.1 Safari/605.1.15

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 4

grade is not defined. Use the function hasPassingGrade() as a condition with correct argument for if condition.

Remove semicolons after functions call within the returning strings. And add parameters totalScores and studentScore within theappropriate function call in the returning strings.

Like this:

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

Your code is not correctly visible. You need to add three back ticks before and after your code block here in your reply.

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

You should call that function, you have reference of the function only.

The returning strings should be exactly the same as test wants. You have some spacing and punctuation issues.
Edit:

studentScores is not defined.

const studentScores = 37;
function studentMsg(totalScores, studentScores) {
  hasPassingGrade();
   if (hasPassingGrade==="F"){
    return "Class average:"+getAverage(totalScores)+"Your grade:"+getGrade(studentScores)+"You failed the course".
  }else{
    return "Class average:"+getAverage(totalScores)+"Your grade:"+getGrade(studentScores)+"You passed the course".
  }
} 


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

You didn’t need to define the studentScores.

You need to correct it by removing s from the end of studentScores in the above grade and and average function calls. Also you isn’t corrected the spacing and punctuation as per required result.

Also you didn’t calling the hasPassingGrade function.

I called hasPassingGrade inside the function

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


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

You need to call the function as if condition for comparing for pass and fail.

You added extra quote marks and added the . dot on wrong place within both strings.

the returning string output should be exactly:

Class average: 71.7. Your grade: F. You passed the course.

sorry for delay in replying

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

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

should I use console.log instead of return because after the return nothing executes

First you need to correct the code as suggested several times in above posts on this topic.
Console logs are already provided for the function in the challenge step. You only need to write the correct code within the function. If you add console logs, instead of return statement. You can’t get a functional result message. Console logs only display the code result to the console.

Im getting close, it passes the message to the console but then at the end says undefined

function studentMsg(totalScores, studentScore) {
  if (hasPassingGrade === "F") {
    console.log(`Class average: ${getAverage(totalScores)}. Your grade: ${getGrade(studentScore)}. You failed the course.`)
  } else {
    console.log(`Class average: ${getAverage(totalScores)}. Your grade:${getGrade(studentScore)}. You passed the course.`)
  }
}

why does it say undefined at the end?

You didn’t calling the function hasPassingGared() within the if condition.

You aren’t returning the message strings. Actually you aren’t following the guide form us. You are doing your own things two pass the code.

should I use template strings

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

I don’t get it, can you give me hints please

You can use anyone.

You need add a correct score argument (choose the correct parameter from the function getResultMsg) to the function hasPassingGrade() within the if condition.

The test wants to return the result. You aren’t returning it. You are logging it to the console.

function studentMsg(totalScores, studentScore) {
  const score = 37;
  if (hasPassingGrade(score) === "F") {
    console.log(`Class average: ${getAverage(totalScores)}. Your grade: ${getGrade(studentScore)}. You failed the course.`,)
  } else {
    console.log(`Class average: ${getAverage(totalScores)}. Your grade:${getGrade(studentScore)}. You passed the course.`,)   
  }
  return hasPassingGrade();
}

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

You didn’t need the above declaration assignment.

Pass the studentScore to hasPassingGrade().

Remove the console.log() from strings. And return the strings using return keyword.

Remove the above return statement.

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

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

I don’t know why it says passed when it should say failed