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?
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