Why the output is not showing correclty?Tell us what’s happening:
Your code so far
function sequentialSizes(val) {
var answer = "";
// Only change code below this line
switch(val) {
case ((val >= 1) && (val <= 3)):
return "Low";
break;
case ((val >= 4) && (val <= 6)):
return "Mid";
break;
case ((val >= 7) && (val <= 9)):
return "High";
break;
}
// Only change code above this line
return answer;
}
// Change this value to test
sequentialSizes(5);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements
1 Like
You can’t put that kind of logic inside of switch statements.
Your cases evaluate to either true or false then you are comparing ‘val’ with true or false which should be a number.
For ex. use this syntax.
case 1:
case 2:
You’re using val in the case checks and you don’t need to. switch operates on the value specified by case, so you’ll need to stack your case statements as indicated in the example on that exercise:
switch(val) {
case 1:
case 2:
case 3:
break;
Why did you use comparison operators?
That’s not what the challenge is teaching.
you should instead put together all values that share the same output like in the following example
case 1:
case 2:
case 3:
Output (return or console.log()....)
break;
Logical operators can be used with IF ELSE IF STATEMENTS.
Good luck.
@Abhimanyu100
You where asked to write a switch statement for the ranges of numbers
1-3
4-6
7-9
and set answer to
"Low"
"Mid"
"High"
Respectively…
Kindly… your code is just checking the condition of val for two numbers each case not a range of the numbers…
Respectfully, please, Ranges of numbers are numbers running through one number orderly. so
1-3 === 1,2,3
4-6 === 4,5,6
7-9 === ? you know the answer
this means your code will have to depend on multiple options for the cases. where
case 1:
case 2:
case 3:
answer = "required string"
break;
Good luck and happy coding, hope this helps.