# Is there logic behind this?

#1

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
console.log(average);
}

const showLetterGrade = gpa => {
/* switch (gpa){
case (gpa>0 && gpa<=59):
return "F";
break;
}*/
if (gpa>0 && gpa<=59){
return 'F';
}
}
``````

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

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

``````switch(boolean):
case boolean:

switch(number)
case number:

switch(string)
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?

#3

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.

#4

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.

#5

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?

#6

`arguments` and `arguments.length`.

#7

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

#8

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.