Tell us what’s happening:
I am not having an issue with the solution to this challenge, moreover, I was playing around and thought that I had another solution by expressing the case ranges using
conditional and logical operators.
I can’t figure out exactly why it does not work. Stepping through the block in VS Code, shows that it goes straight to the final return statement, bypassing all of the cases. I’ve tried adding “return answer =” to each case and other minor permutations.
Am I using the syntax in the case statements wrong. Is this even possible, and if so, how?
Your code so far
function sequentialSizes(val) {
let answer = "";
// Only change code below this line
switch (val) {
case (val >= 1 && val <= 3):
answer = "Low";
break;
case (val >= 4 && val <= 6):
answer = "Mid";
break;
case (val >= 7 && val <= 9):
answer = "High";
break;
}
// Only change code above this line
return answer;
}
console.log(sequentialSizes(3));
Challenge: Basic JavaScript - Multiple Identical Options in Switch Statements
Link to the challenge: