Is there logic behind this?



when I try to run the code below for switch, it fails (goes for the undefined) however when I try the same logic for if when comparing if the number is in-between two other numbers, it works. Is there logic behind this? otherwise I understand that only way to understand if a number is in-between 2 other numbers is if/else if statement but not switch. I prefer switch because it’s easier to read and read since everything is under one curly braces.

const finalGrade = (n1,n2,n3)=>{
  let average = (n1+n2+n3)/3
  return showLetterGrade(average);

const showLetterGrade = gpa => {
 /* switch (gpa){
    case (gpa>0 && gpa<=59):
      return "F";
  if (gpa>0 && gpa<=59){
    return 'F';
console.log(finalGrade(40, 42, 45))

FAQ: Code Challenges: JavaScript Fundamentals - finalGrade()
FAQ: Code Challenges: JavaScript Fundamentals - finalGrade()

The logic is simple… When the switch parameter matches the case, that branch is followed.

case boolean:

case number:

case string:

gpa is a value (a number). Are there any cases that match this?

This is a contradiction of terms. You do understand what GPA means?


A switch normally only has one boolean check per case statement.

This person had the same type of problem.

The above link has 2 different ways to solve this.


You need to check the boolean of the case vs a boolean of the switch(expr).
Just change it to switch(true) then run… also make sure the default sentence has a (.) otherwise it will still show as not solved.


is there a way that you can make that you can add (as a argument) as many grades as you want? and if yes, then how do you make that the average should automatically divide according to how many grades you’ve entered?


arguments and arguments.length.


oh, so you make /arguments.length! but how do you add? i dont understand what i am suppose to do with the arguments


Sum of an array? Nothing special there.
I generally prefer to represent things in data rather than code - so I’d use a single argument, an array.