Files

75 lines
1.5 KiB
Markdown
Raw Normal View History

2018-10-12 15:37:13 -04:00
---
title: Multiple Identical Options in Switch Statements
---
# Multiple Identical Options in Switch Statements
2018-10-12 15:37:13 -04:00
## Code Solutions
2018-10-12 15:37:13 -04:00
<details><summary>Solution 1 (Click to Show/Hide)</summary>
2018-10-12 15:37:13 -04:00
```javascript
function sequentialSizes(val) {
var answer = "";
// Only change code below this line
switch (val) {
2018-10-12 15:37:13 -04:00
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
return answer;
2018-10-12 15:37:13 -04:00
}
// Change this value to test
sequentialSizes(1);
```
</details>
<details><summary>Solution 1 (Click to Show/Hide)</summary>
2018-10-12 15:37:13 -04:00
```javascript
function sequentialSizes(val) {
var answer = "";
// Only change code below this line
switch (val) {
case 1:
case 2:
case 3:
2018-10-12 15:37:13 -04:00
answer = "Low";
break;
case 4:
case 5:
case 6:
2018-10-12 15:37:13 -04:00
answer = "Mid";
break;
case 7:
case 8:
case 9:
2018-10-12 15:37:13 -04:00
answer = "High";
}
// Only change code above this line
return answer;
2018-10-12 15:37:13 -04:00
}
// Change this value to test
sequentialSizes(1);
```
#### Code Explanation
2018-10-12 15:37:13 -04:00
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.
#### Relevant Links
- ["Switch: Methods for multi-criteria case" - *MDN JavaScript Reference*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch)
</details>