Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start a switch statement that checks the variable color.
Javascript
switch([1]) { case 'red': console.log('Red color'); break; default: console.log('Unknown color'); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that is not defined or unrelated to the switch.
Leaving the parentheses empty.
✗ Incorrect
The switch statement must check the variable
color to decide which case to execute.2fill in blank
mediumComplete the code to add a case for the value 'blue' that logs 'Blue color'.
Javascript
switch(color) {
case 'red':
console.log('Red color');
break;
case [1]:
console.log('Blue color');
break;
default:
console.log('Unknown color');
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the case value.
Using a different color string than 'blue'.
✗ Incorrect
The case must match the string 'blue' to handle that color correctly.
3fill in blank
hardFix the error by completing the code to properly end the switch statement.
Javascript
switch(color) {
case 'red':
console.log('Red color');
break;
default:
console.log('Unknown color');
[1]
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'end' which is not valid in JavaScript.
Using 'break;' outside a case block.
Using 'return' which is not the block end.
✗ Incorrect
The switch statement must be closed with a closing curly brace '}'.
4fill in blank
hardFill both blanks to create a switch that logs 'Small' for 1, 'Medium' for 2, and 'Large' for 3.
Javascript
switch([1]) { case 1: console.log('Small'); break; case [2]: console.log('Medium'); break; case 3: console.log('Large'); break; default: console.log('Unknown size'); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong variable name in the switch expression.
Using a case value that does not match the intended number.
✗ Incorrect
The switch must check the variable 'size' and the second case must be 2 to match 'Medium'.
5fill in blank
hardFill both blanks to create a switch that logs the day name for 1, 2, and 3.
Javascript
switch([1]) { case 1: console.log([2]); break; case 2: console.log('Tuesday'); break; case 3: console.log('Wednesday'); break; default: console.log('Invalid day'); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong variable name in the switch expression.
Not using quotes around the day name strings.
✗ Incorrect
The switch checks the variable 'day'. For case 1, it logs 'Monday'. The second blank is the string 'Monday' to print.