Show "start" for Monday using a switch. The day is Monday.
Acceptance criteria
- 1.#out should show start.
JavaScript Tutorial · JavaScript Conditions
These 10 tasks go with the JavaScript switch Statement chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “The JavaScript switch statement is used to perform different actions based on different values.” .
1.Switch on a dayexercise · easy · 10 min
Show "start" for Monday using a switch. The day is Monday.
Passes when: #out should show start.
2.Use the default caseexercise · easy · 10 min · practice plan
An unknown colour should fall through to "unknown".
Passes when: #out should show unknown.
3.Group two casesexercise · easy · 10 min · practice plan
Both "Sat" and "Sun" should show "weekend". The day is Sun.
Passes when: #out should show weekend.
4.Switch on a numberexercise · easy · 10 min · practice plan
Show "two" when the value is 2.
Passes when: #out should show two.
5.Return a label from a switchexercise · medium · 10 min · practice plan
Map the status code 404 to "not found".
Passes when: #out should show not found.
6.Fix the missing breakbug fix · easy · 8 min
Without a break the next case runs and overwrites the answer.
Passes when: #out should show one.
7.Fix the strict type mismatchbug fix · easy · 8 min · practice plan
switch compares strictly, so a string never matches a number case.
Passes when: #out should show two.
8.Fix the missing defaultbug fix · easy · 8 min · practice plan
An unmatched value leaves the output blank.
Passes when: #out should show unknown.
9.Fix the wrong case valuebug fix · easy · 8 min · practice plan
The case tests the wrong day, so it falls to the default.
Passes when: #out should show weekend.
10.Fix the case-sensitive matchbug fix · easy · 8 min · practice plan
The case uses different capitalisation, so nothing matches.
Passes when: #out should show start.
Between them these tasks cover switch/case, break and default.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.