2018-10-04 13:37:37 +00:00
---
id: 56533eb9ac21ba0edf2244df
title: Multiple Identical Options in Switch Statements
challengeType: 1
2019-02-14 17:24:02 +00:00
videoUrl: 'https://scrimba.com/c/cdBKWCV'
2019-07-31 18:32:23 +00:00
forumTopicId: 18242
2021-01-13 02:31:00 +00:00
dashedName: multiple-identical-options-in-switch-statements
2018-10-04 13:37:37 +00:00
---
2020-11-27 18:02:05 +00:00
# --description--
If the `break` statement is omitted from a `switch` statement's `case` , the following `case` statement(s) are executed until a `break` is encountered. If you have multiple inputs with the same output, you can represent them in a `switch` statement like this:
2019-05-17 13:20:30 +00:00
```js
2020-11-09 17:09:21 +00:00
var result = "";
2019-05-17 13:20:30 +00:00
switch(val) {
case 1:
case 2:
case 3:
result = "1, 2, or 3";
break;
case 4:
result = "4 alone";
}
```
2018-10-04 13:37:37 +00:00
Cases for 1, 2, and 3 will all produce the same result.
2020-11-27 18:02:05 +00:00
# --instructions--
Write a switch statement to set `answer` for the following ranges:
2021-03-03 00:12:12 +00:00
`1-3` - `Low`
`4-6` - `Mid`
`7-9` - `High`
2020-11-27 18:02:05 +00:00
2021-03-03 00:12:12 +00:00
**Note:** You will need to have a `case` statement for each number in the range.
2020-11-27 18:02:05 +00:00
# --hints--
2021-03-03 00:12:12 +00:00
`sequentialSizes(1)` should return the string `Low`
2020-11-27 18:02:05 +00:00
```js
assert(sequentialSizes(1) === 'Low');
```
2021-03-03 00:12:12 +00:00
`sequentialSizes(2)` should return the string `Low`
2020-11-27 18:02:05 +00:00
```js
assert(sequentialSizes(2) === 'Low');
2018-10-04 13:37:37 +00:00
```
2021-03-03 00:12:12 +00:00
`sequentialSizes(3)` should return the string `Low`
2018-10-04 13:37:37 +00:00
2020-11-27 18:02:05 +00:00
```js
assert(sequentialSizes(3) === 'Low');
```
2018-10-04 13:37:37 +00:00
2021-03-03 00:12:12 +00:00
`sequentialSizes(4)` should return the string `Mid`
2020-11-27 18:02:05 +00:00
```js
assert(sequentialSizes(4) === 'Mid');
```
2021-03-03 00:12:12 +00:00
`sequentialSizes(5)` should return the string `Mid`
2020-11-27 18:02:05 +00:00
```js
assert(sequentialSizes(5) === 'Mid');
```
2021-03-03 00:12:12 +00:00
`sequentialSizes(6)` should return the string `Mid`
2020-11-27 18:02:05 +00:00
```js
assert(sequentialSizes(6) === 'Mid');
```
2021-03-03 00:12:12 +00:00
`sequentialSizes(7)` should return the string `High`
2020-11-27 18:02:05 +00:00
```js
assert(sequentialSizes(7) === 'High');
```
2021-03-03 00:12:12 +00:00
`sequentialSizes(8)` should return the string `High`
2020-11-27 18:02:05 +00:00
```js
assert(sequentialSizes(8) === 'High');
```
2021-03-03 00:12:12 +00:00
`sequentialSizes(9)` should return the string `High`
2020-11-27 18:02:05 +00:00
```js
assert(sequentialSizes(9) === 'High');
```
You should not use any `if` or `else` statements
```js
assert(!/else/g.test(code) || !/if/g.test(code));
```
You should have nine `case` statements
```js
assert(code.match(/case/g).length === 9);
```
# --seed--
## --seed-contents--
2018-10-04 13:37:37 +00:00
```js
function sequentialSizes(val) {
var answer = "";
// Only change code below this line
2018-10-08 00:01:53 +00:00
// Only change code above this line
return answer;
2018-10-04 13:37:37 +00:00
}
sequentialSizes(1);
```
2020-11-27 18:02:05 +00:00
# --solutions--
2018-10-04 13:37:37 +00:00
```js
function sequentialSizes(val) {
var answer = "";
2018-10-08 00:01:53 +00:00
2018-10-04 13:37:37 +00:00
switch(val) {
case 1:
case 2:
case 3:
answer = "Low";
break;
case 4:
case 5:
case 6:
answer = "Mid";
break;
case 7:
case 8:
case 9:
answer = "High";
}
2018-10-08 00:01:53 +00:00
return answer;
2018-10-04 13:37:37 +00:00
}
```