I have a question. Why is 'undefined coming out?'

// Write your function here: const finalGrade = (a,b,c)=> { let average = (a+b+c)/3; if ((a>100 || a < 0) ||(b>100 || b < 0)||(c>100 || c< 0)) return 'You have entered an invalid grade.'; switch (average){ case (0 <= average) && (average <= 60) : return 'F'; break; case (60 <= average) && (average <= 70) : return 'D'; break; case (70 <= average) && (average <= 80) : return 'C'; break; case (80 <= average) && (average <= 90) : return 'B'; break; case (90 <= average) && (average <= 100) : return 'A'; break; } } console.log(finalGrade(99, 92, 95)) // Should print 'A' // We encourage you to add more function calls of your own to test your code!

Why is ‘undefined’ coming out as an output?

that means no return keyword is reached, and thus you get undefined

you can’t use switch like that. Switch does equality (===) comparison with the cases

if you really want to use switch, you should do switch(true)

Why can’t I use switch this way?
Thnx for the reply btw

I covered this:

switch is useful when you have specific values, not when you have ranges like you have

I got it. Thank you :slight_smile: