Files

41 lines
644 B
Markdown
Raw Normal View History

2018-10-12 15:37:13 -04:00
---
title: Adding a Default Option in Switch Statements
---
# Adding a Default Option in Switch Statements
---
## Hints
### Hint 1
Adding a default option makes sure that in case your variable doesn't match any of the options, the default will be used.
---
## Solutions
<details><summary>Solution 1 (Click to Show/Hide)</summary>
2018-10-12 15:37:13 -04:00
```javascript
function switchOfStuff(val) {
var answer = "";
switch (val) {
case "a":
answer = "apple";
break;
case "b":
answer = "bird";
break;
case "c":
answer = "cat";
break;
default:
answer = "stuff";
2018-10-12 15:37:13 -04:00
}
return answer;
2018-10-12 15:37:13 -04:00
}
```
</details>