Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check the value of color using an if statement.
Javascript
if (color [1] 'red') { console.log('Color is red'); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using = instead of === causes assignment instead of comparison.
Using == can cause unexpected type coercion.
✗ Incorrect
Use the strict equality operator === to compare values in JavaScript.
2fill in blank
mediumComplete the switch statement to handle the case when day is 'Monday'.
Javascript
switch(day) {
case [1]:
console.log('Start of the work week');
break;
default:
console.log('Another day');
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around string case labels.
Using the wrong day string.
✗ Incorrect
The case label must match the value you want to check, here 'Monday'.
3fill in blank
hardFix the error in the if-else statement to correctly check if score is greater than 50.
Javascript
if (score [1] 50) { console.log('Passed'); } else { console.log('Failed'); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using = instead of > causes assignment, not comparison.
Using < checks the wrong condition.
✗ Incorrect
Use > to check if score is greater than 50.
4fill in blank
hardFill both blanks to create a switch statement that logs 'Weekend' for Saturday and Sunday.
Javascript
switch(day) {
case [1]:
case [2]:
console.log('Weekend');
break;
default:
console.log('Weekday');
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using weekdays instead of weekend days.
Forgetting to include both weekend days.
✗ Incorrect
Use 'Saturday' and 'Sunday' as case labels to group weekend days.
5fill in blank
hardFill all three blanks to create an if-else chain that logs the correct message for fruit.
Javascript
if (fruit [1] 'apple') { console.log('Apple pie'); } else if (fruit [2] 'banana') { console.log('Banana smoothie'); } else { console.log([3]); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of === can cause unexpected results.
Not using quotes around the string in the else block.
✗ Incorrect
Use strict equality === for comparisons and a string for the default message.