Multiple Identical Options in Switch Statements

Solutions

Solution 1 (Click to Show/Hide)
``````function sequentialSizes(val) {
// Only change code below this line
switch (val) {
case 1:
case 2:
case 3:
return "Low";
break;
case 4:
case 5:
case 6:
return "Mid";
break;
case 7:
case 8:
case 9:
return "High";
break;
}
// Only change code above this line
}
// Change this value to test
sequentialSizes(1);
``````
Solution 1 (Click to Show/Hide)
``````function sequentialSizes(val) {
// Only change code below this line
switch (val) {
case 1:
case 2:
case 3:
break;
case 4:
case 5:
case 6:
break;
case 7:
case 8:
case 9:
}
// Only change code above this line
}
// Change this value to test
sequentialSizes(1);
``````

Code Explanation

Since you already have a variable named `answer` defined and the function returns it, you can just modify its value on each group of case statements to fit the exercise requirements.

4 Likes

function sequentialSizes(val) {
// Only change code below this line
switch (val) {
case β1β:
case β2β:
case β3β:
break;
case β4β:
case β5β:
case β6β:
break;
case β7β:
case β8β:
case β9β:
}

// Only change code above this line
}

// Change this value to test
sequentialSizes(2);

This is not the solutionβ¦but close try and find where I went wrong.

4 Likes

I struggled with this one for a while. I knew I had it, but it would not give me the last check 'must have 9 cases.'
I noticed I had put a short comment in exactly where it is here. I removed it and it worked. I wonder how many times this has happened before and we never realized it?

anyone know how to solve this

function sequentialSizes(val) {
// Only change code below this line
switch(val) {
case 1:
case 2:
case 3:
break;
case 4:
case 5:
case 6:
break;
case 7:
case 8:
case 9:
break;
}

// Only change code above this line
}

// Change this value to test
sequentialSizes(1);

i put my working code above but try it on your own. the thing i got caught up on was i didnβt add the switch(val) at the beginning i just started going straight into cases

Just remove ββ from, caseβ¦ correct code is-
function sequentialSizes(val) {
// Only change code below this line
switch(val){
case 1:
case 2:
case 3:
break;
case 4:
case 5:
case 6:
break;
case 7:
case 8:
case 9:
break;
}

// Only change code above this line
}

// Change this value to test
console.log(sequentialSizes(1));

1 Like

Challenge is faced on that code of yours is the You should have nine case statements test case. But I figured out a way to passed it. Thanks guys for the contribution. Looks like this activity is not explained well but I learned a lot.

remove the quotes in the cases

There should not be quotes around the numbers.

function sequentialSizes(val) {
// Only change code below this line
switch (val) {
case 1:
case 2:
case 3:
break;
case 4:
case 5:
case 6: