Building a gradebook app step 2

heres my code but it wont pass

function getGrade(score) {
  if (getGrade = 100)
 return 'A++'
} else if (getGrade =< 99)
  return 'A'
  } else if (getGrade =< 89)
  return 'B'
  } else if (getGrade =< 79)
  return 'C'
  } else if (getGrade =< 69)
  return 'D'
  } else 'F'


console.log(getGrade(96));
console.log(getGrade(82));
console.log(getGrade(56));

Please post a link to the step. Please talk about how you have attempted to debug this code.

i dont know anything about debugging

Have you tried anything to figure out what might be wrong? That’s called “debugging”

no someone told me not to use chat gpt which is the only thing that helps me with the mistakes

well yeah i have went to other websites to see how to write the if else statements but the examples are different than the tutorial im doing

ChatGPT doesn’t know how to code, so I wouldn’t use that to help you write your code.

It looks like you are trying to write an if-else statement. Do you remember where you’ve seen those before? How does your if-else statement look different than other examples?

i dont know the exact lesson it could take a few hours to look through them all again

I can’t write the solution for you.

You said above you have looked at other examples of if-else statements. How does yours look different than those examples?

const distribution = {
  A: 90,
  B: 80,
  C: 70,
  D: 60,
  F: 0
};

const getGrade = (score, distribution, maxScore = 100, minScore = 0) => {

  // Handle edge cases
  if (score > maxScore || score < minScore) {
    return "Error";
  }
  // Get an array of the letter grades
  const grades = Object.keys(distribution);

  // Sort the grades in descending order of the floor score of each grade
  grades.sort((a, b) => distribution[b] - distribution[a]);

  // Since the grades are sorted, the first grade to be lower than the score will be the correct grade to return
  const grade = grades.find(grade => distribution[grade] <= score);

  // No + or - for bottom grade
  if (grade === grades[grades.length - 1]) {
    return grade
  } else if (score - distribution[grade] <= 2) { // check and return "-" grades
    return grade += "-"
  } else if (score - distribution[grade] >= 8) { // check and return "+" grades
    return grade += "+"
  } else { // return normal grades
    return grade
  }

///example 2

function myGrading (score) {

  // Edge cases
  if (score < 0 || score > 100) return 'INVALID SCORE';
  if (score == 100) return 'A+';

  // Important values
  var decimal = score % 10;
  score = Math.floor(score / 10); // <- here we reduce the range to 0-9

              // 0    1    2    3    4    5    6    7    8    9
  var scores = ['F', 'F', 'F', 'F', 'F', 'F', 'D', 'C', 'B', 'A'];
  var grade = scores[score];

  if (grade != 'F') {
    if (decimal <= 2) grade += '-';
    else if (decimal >= 8) grade += '+';
  }

  return grade;
}

// example 3

const age = 12;

if (age >= 18) {
 console.log("Nick is an adult.");
} else {
 console.log("Nick is a child.");
}

Can you talk about how your syntax looks different that the syntax in those examples?

(Note - I wouldn’t look up examples of how to pass this exact exercise. That isn’t the point of the “Review” courses. You are supposed to practice thinking up ways to approach problems.)

well my code starts with a function then it has a set of if else statements underneath it.

one of the other codes start with a variable and a list of scores underneath it. then it has another variable underneath it that says ‘score’ ‘distrobution’ ‘max score’ 100, min score

btw is there a lesson online that teaches how to think up ways to approach problems since we dont have to remember syntax?

I’d start comparing the basic parts of the syntax

How are these different?

const age = 12;

if (age >= 18) {
console.log(“Nick is an adult.”);
} else {
console.log(“Nick is a child.”);
}

this code isnt written in a function mine is. this code does not provide a range of two numbers like 99-90

Go on, there are many differences. Focus on the syntax I quoted. You wrote your if statement differently than the example

i am using return theres no console log after each ‘if else’ because they are already pre written at the bottom

Lets go even simpler. How are these lines different?

ones >= and the other is =

Please say more