2018-10-10 18:03:03 -04:00
---
id: 56533eb9ac21ba0edf2244df
2021-02-06 04:42:36 +00:00
title: Multiple Identical Options in Switch Statements
2018-10-10 18:03:03 -04:00
challengeType: 1
2020-04-29 18:29:13 +08:00
videoUrl: 'https://scrimba.com/c/cdBKWCV'
forumTopicId: 18242
2021-01-13 03:31:00 +01:00
dashedName: multiple-identical-options-in-switch-statements
2018-10-10 18:03:03 -04:00
---
2020-12-16 00:37:30 -07:00
# --description--
2021-02-06 04:42:36 +00:00
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:
2020-04-29 18:29:13 +08:00
```js
2021-02-06 04:42:36 +00:00
var result = "";
2020-04-29 18:29:13 +08:00
switch(val) {
case 1:
case 2:
case 3:
result = "1, 2, or 3";
break;
case 4:
result = "4 alone";
}
```
2021-02-06 04:42:36 +00:00
Cases for 1, 2, and 3 will all produce the same result.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --instructions--
2021-02-06 04:42:36 +00:00
Write a switch statement to set `answer` for the following ranges:
2020-12-16 00:37:30 -07:00
`1-3` - "Low"
`4-6` - "Mid"
`7-9` - "High"
2021-02-06 04:42:36 +00:00
**Note**
You will need to have a `case` statement for each number in the range.
2020-12-16 00:37:30 -07:00
# --hints--
2021-02-06 04:42:36 +00:00
`sequentialSizes(1)` should return "Low"
2020-12-16 00:37:30 -07:00
```js
assert(sequentialSizes(1) === 'Low');
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
`sequentialSizes(2)` should return "Low"
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(sequentialSizes(2) === 'Low');
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`sequentialSizes(3)` should return "Low"
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(sequentialSizes(3) === 'Low');
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`sequentialSizes(4)` should return "Mid"
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(sequentialSizes(4) === 'Mid');
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`sequentialSizes(5)` should return "Mid"
2020-12-16 00:37:30 -07:00
```js
assert(sequentialSizes(5) === 'Mid');
```
2021-02-06 04:42:36 +00:00
`sequentialSizes(6)` should return "Mid"
2020-12-16 00:37:30 -07:00
```js
assert(sequentialSizes(6) === 'Mid');
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`sequentialSizes(7)` should return "High"
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(sequentialSizes(7) === 'High');
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
`sequentialSizes(8)` should return "High"
2020-12-16 00:37:30 -07:00
```js
assert(sequentialSizes(8) === 'High');
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`sequentialSizes(9)` should return "High"
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(sequentialSizes(9) === 'High');
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
You should not use any `if` or `else` statements
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(!/else/g.test(code) || !/if/g.test(code));
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
You should have nine `case` statements
2020-04-29 18:29:13 +08:00
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(code.match(/case/g).length === 9);
2018-10-10 18:03:03 -04:00
```
2020-04-29 18:29:13 +08:00
2021-01-13 03:31:00 +01:00
# --seed--
## --seed-contents--
```js
function sequentialSizes(val) {
var answer = "";
// Only change code below this line
// Only change code above this line
return answer;
}
sequentialSizes(1);
```
2020-12-16 00:37:30 -07:00
# --solutions--
2021-01-13 03:31:00 +01:00
```js
function sequentialSizes(val) {
var answer = "";
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";
}
return answer;
}
```