I also thought of using a switch, but as you can see by the comments here, using switch(true) and then doing evaluations in each case is kind of an anti-pattern that can be hard to read and debug.
I would avoid and look for one of the other conditional options in this board.
To further clarify for those still confused on why passing in switch(value) doesn't work, it's because it's comparing a Boolean to a numerical one, which will always be false. Say our average is 95 and we're assigning that to a variable avg. If we try to pass in avg as the argument to the switch statement's parameter, this is essentially what is happening:
switch(avg) { //avg == 95
case (avg >= 90): //comparing 95 to true, which is false
return 'A';
(avg >= 90) is returning a Boolean. We'll never reach a switch statement that evaluates to true if we're passing in our avg variable as the argument. I hope this helps!
wow, this is so clean code!
I'm from Indonesian
clearly didn't read the description
Mutating an argument is the worst thing you can do.
I also thought of using a switch, but as you can see by the comments here, using switch(true) and then doing evaluations in each case is kind of an anti-pattern that can be hard to read and debug.
I would avoid and look for one of the other conditional options in this board.
This is what I did. Awesome job!
wow, so good
good blesss.
you can do this if you have exactly one parameter.
cool , I did this the same way but put the 'list' parameter into parenthesis,dindn't know I could do it without it.
This comment is hidden because it contains spoiler information about the solution
good solving:)
same sol ^^
no substring ? wot´s this dark magic ?
So clever.
To further clarify for those still confused on why passing in
switch(value)
doesn't work, it's because it's comparing a Boolean to a numerical one, which will always befalse
. Say our average is 95 and we're assigning that to a variableavg
. If we try to pass inavg
as the argument to the switch statement's parameter, this is essentially what is happening:(avg >= 90)
is returning a Boolean. We'll never reach a switch statement that evaluates to true if we're passing in ouravg
variable as the argument. I hope this helps!Loading more items...