thecodezone.
The Code Zone
Short steps, at your pace · Free lessons and practice · Member video walkthroughs
Save your next small win.

Checking your account…

08.05 · Switch statements / Practice · 4 min

Give Sunday its shared case

Saturday works, but Sunday misses its category. Let two labels share the same response.

Activity 5 of 7 in Switch statements

All courses

JavaScript Basics / 08.05

Give Sunday its shared case

Not started

Group both weekend days before one response.

More options
Rob studies a highlighted weekend calendar and compares two day cards with a planning notebook.
Rob’s comic strip · Switch statements

Match a delivery method with switch

Work through 3 focused steps. Read the explanation, type each requested change and check it before moving on. Your own code carries forward.

The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.

Start mini-lesson(opens in a new tab)

3 steps · Saved work · Instant feedback

YOUR TURN

Give Sunday its shared case

Print Weekday for Monday through Friday, Weekend for Saturday or Sunday, and Unknown day otherwise. Keep the grouped case structure. Add Sunday to the shared weekend group so the starting Sunday input prints Weekend.

Expected output
Weekend

Keep the starting inputs. Print these lines in this order, without extra output.

Edit JavaScript, then run it. Check Challenge shows which output checks pass or need a fix. Word wrap is enabled.

Ready to checkRun the checks to see your results here.

Work in VS Code instead

Copy the starter into a file named practice.js in VS Code. If Node.js is installed, open the terminal in that folder and run node practice.js. Compare the output with the task above. Automated challenge checks are available in the browser editor.

Code example
example.jsjavascript · example
const day = "Sunday";

switch (day) {
  case "Monday":
  case "Tuesday":
  case "Wednesday":
  case "Thursday":
  case "Friday":
    console.log("Weekday");
    break;
  case "Saturday":
    console.log("Weekend");
    break;
  default:
    console.log("Unknown day");
}

Need a nudge?

One response can serve several labels

The weekday labels already lead to one block. The weekend can use that same pattern.

Add a label before the existing response

Put case "Sunday": beside case "Saturday":, before the Weekend log. Keep the break after their shared response.

Reveal a possible solution
One possible solution
example.jsjavascript · example
const day = "Sunday";

switch (day) {
  case "Monday":
  case "Tuesday":
  case "Wednesday":
  case "Thursday":
  case "Friday":
    console.log("Weekday");
    break;
  case "Saturday":
  case "Sunday":
    console.log("Weekend");
    break;
  default:
    console.log("Unknown day");
}

Try Saturday, Monday and Funday: Weekend, Weekday, Unknown day. Case matching is case-sensitive; sunday is not Sunday. Sharing empty case labels is deliberate fall-through. Leaving out a needed break after a response is a different issue.

Replace your editor code?

Your current work will be replaced. Choose Cancel to keep it.

Ready to try it?

Practice in your browser and see your results.

Progress details

Have a question?

Ask the Code Zone community.

Ask a question in The Code Zone (opens in a new tab)

Continue learning

ONE STEP FORWARD

Several labels can share a response. Keep the break after the shared statements.