JavaScript bootcamp · Lab 45

Day name

easySwitch10 minLesson: Switch

Read the question, write JavaScript on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

Read 1–7; print Monday…Sunday. Anything else: Invalid.

Input. One integer.

Output. Day name or Invalid.

Examples

Example 1
Input
1
Output
Monday
Example 2
Input
7
Output
Sunday
Example 3
Input
0
Output
Invalid
Hint
  1. const days = ['','Monday',...]
Show correct code

Peek only after you have tried. You can still Check your own version.

const d = Number(readLine());
const days = ['', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
console.log(days[d] || 'Invalid');
main.jsconsole.log · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.