Build a Gradebook App - Build a Gradebook App

Tell us what’s happening:

I just need to get over the stupid requirement 22 about student msg and i need to know were to put the fix at

Your code so far

// 1. getAverage function to calculate the average score
function getAverage(scores) {
  const total = scores.reduce((acc, score) => acc + score, 0); // sum all scores
  return total / scores.length; // divide by the number of scores
}

// 2. getGrade function to return a grade based on score
function getGrade(score) {
  if (score === 100) return "A+";
  if (score >= 90) return "A";
  if (score >= 80) return "B";
  if (score >= 70) return "C";
  if (score >= 60) return "D";
  return "F"; // If score is below 60
}

// 3. hasPassingGrade function to check if a score is a passing grade
function hasPassingGrade(score) {
  const grade = getGrade(score);
  return grade !== "F"; // Return true if the grade is not "F"
}

// 4. studentMsg function to generate a message for the student
function studentMsg(scores, studentScore) {
  const classAverage = getAverage(scores); // Calculate class average
  const studentGrade = getGrade(studentScore); // Get the student's grade
  const passed = hasPassingGrade(studentScore); // Check if the student passed
  
  // Return the message based on the pass/fail status
  if (passed) {
    return `Class average: ${classAverage.toFixed(1)}. Your grade: ${studentGrade}. You passed the course.`;
  } else {
    return `Class average: ${classAverage.toFixed(1)}. Your grade: ${studentGrade}. You failed the course.`;
  }
}

// Example Test Cases
console.log(getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89])); // Should return 71.7
console.log(getGrade(92)); // Should return "A"
console.log(hasPassingGrade(92)); // Should return true
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37)); // Should return failure message
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100)); // Should return success message

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36

Challenge Information:

Build a Gradebook App - Build a Gradebook App

Hi there and welcome to our community!

Your code is fine except that you don’t need to use the toFixed() method. Remove that and you should pass all tests.

It is still saying the dumb step 22 is messing it up

please share your updated code

here it is

// 1. getAverage function to calculate the average score
function getAverage(scores) {
  const total = scores.reduce((acc, score) => acc + score, 0); // sum all scores
  return total / scores.length; // divide by the number of scores
}

// 2. getGrade function to return a grade based on score
function getGrade(score) {
  if (score === 100) return "A+";
  if (score >= 90) return "A";
  if (score >= 80) return "B";
  if (score >= 70) return "C";
  if (score >= 60) return "D";
  return "F"; // If score is below 60
}

// 3. hasPassingGrade function to check if a score is a passing grade
function hasPassingGrade(score) {
  const grade = getGrade(score);
  return grade !== "F"; // Return true if the grade is not "F"
}

// 4. studentMsg function to generate a message for the student
function studentMsg(scores, studentScore) {
  const classAverage = getAverage(scores); // Calculate class average
  const studentGrade = getGrade(studentScore); // Get the student's grade
  const passed = hasPassingGrade(studentScore); // Check if the student passed
  
  // Return the message based on the pass/fail status
  if (passed) {
    return `Class average: ${classAverage.toFixed(1)}. Your grade: ${studentGrade}. You passed the course.`;
  } else {
    return `Class average: ${classAverage.toFixed(1)}. Your grade: ${studentGrade}. You failed the course.`;
  }
}

// Example Test Cases
console.log(getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89])); // Should return 71.7
console.log(getGrade(92)); // Should return "A"
console.log(hasPassingGrade(92)); // Should return true
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37)); // Should return failure message
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100)); // Should return success message

Refer to the post from @igorgetmeabrain. You’re still using toFixed()!

I dont know how to not and what section that is

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

you used the toFixed() method somewhere, I am worried you are not aware of that. Did you write that code yourself?

You don’t know how to not use the .toFixed() method, is that correct?

yes my friend wrote this perticular code cause i was to mad to contnie but i am re watching the past lectures and am tring to do that

please write the code yourself, asking for help on code you did not write is not helpful for your learning

Do you often switch off writing code with your friend?

Aren’t you trying to learn this yourself?

1 Like

we do a colabe thing for the coding class we are in so we switch off on each lesson

I have just got into contact with my friend and he suggested i re watch a few video and do a few steps but i fixed it all up
– removed by mod

if you don’t write code you are not going to learn, I suggest you to not skip lessons

In this one you seem to have switched off in the middle of the task?

It is great that you solved the challenge,please don’t post your full working solution.

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.

That’s great you were able to solve the problem when the solution was provided for you right here:

What videos did you watch though, I’m curious?

1 Like

oky I am sorry did not relise