Build a Gradebook App - Build a Gradebook App

Tell us what’s happening:

My functions are returning correct results but unable to clear test cases. hasPassingGrade function is returning false for grade “F” but i am still unable to clear this test case.
Also studentMsg function is eturning correct msg i have checked for spaces punctuation and everything but still unable to clear all the test related to this function.

Your code so far

/*const getAverage = (scores)=>{
  let sum = scores.reduce((acc, curr)=>{
    return acc+curr
  },0)
  let avg = sum/scores.length;
  return avg;
}

const getGrade = (score)=>{
  if(score==100){
    return 'A+'
  }else if(score>=90 && score<=99){
    return 'A'
  }else if(score>=80 && score<=89){
    return 'B'
  }else if (score>= 70 && score<=79){
    return "C"
  }else if (score>=60 && score<= 69){
    return "D"
  }
    return "F"
  
}

const hasPassingGrade = (grade)=>{
  if(grade==="F"){
    return false
  }
   return true 
  
};

const studentMsg = (avg, studentGrade)=>{
   //getAverage(avg);
    let grade = getGrade(studentGrade);
  if(hasPassingGrade(grade)){
    return `Class average: ${avg.toFixed(1)}. Your grade: ${grade}. You passed the course.`
  }else{
    return `Class average: ${avg.toFixed(1)}. Your grade: ${grade}. You failed the course.`
  }
}

let avg = getAverage([56, 23, 89, 42, 75, 11, 68, 34, 91, 19]);
console.log(avg);

let grade = getGrade(77);
console.log(grade);

let passingGrade = hasPassingGrade(grade);
console.log(passingGrade);

let passingMsg = studentMsg(avg, 100);
console.log(passingMsg);

console.log(studentMsg(50.8, 100));*/

const getAverage = (scores) => {
  console.log(scores);
  let sum = scores.reduce((acc, curr) => acc + curr, 0);
  let avg = sum / scores.length;
  return avg;
};

const getGrade = (score) => {
  if (score === 100) {
    return 'A+';
  } else if (score >= 90 && score <= 99) {
    return 'A';
  } else if (score >= 80 && score <= 89) {
    return 'B';
  } else if (score >= 70 && score <= 79) {
    return 'C';
  } else if (score >= 60 && score <= 69) {
    return 'D';
  } else {
    return 'F';
  }
};

const hasPassingGrade = (grade) => {
  if (grade === "F") {
    return false;  // returns false for 'F'
  }
  return true;  // returns true for any other grade
};

const studentMsg = (avg, studentGrade) => {
  let grade = getGrade(studentGrade); // Get the grade based on the student's score
  if (hasPassingGrade(grade)) {
    return `Class average: ${avg.toFixed(1)}. Your grade: ${grade}. You passed the course.`;
  } else {
    return `Class average: ${avg.toFixed(1)}. Your grade: ${grade}. You failed the course.`;
  }
};



// Example:
let avg = getAverage([56, 23, 89, 42, 75, 11, 68, 34, 91, 19]);
//console.log(avg);  // This will print the average

let grade = getGrade(77);  // Get grade based on student's score
//console.log(grade);  // This will print the grade

let passingMsg = studentMsg(avg, 34);  // Test the final message
console.log(passingMsg);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36

Challenge Information:

Build a Gradebook App - Build a Gradebook App

You are considering that a letter is passed to hasPassingGrade, but the requirement is to have it receive a score (a number):

You should have a function named hasPassingGrade that takes a score as a parameter

next, nowhere you are asked to round

1 Like