Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start a switch statement on variable day.
Go
switch [1] { case "Monday": println("Start of the week") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using a variable name that does not exist like
days or Day.Forgetting to put the variable after
switch.โ Incorrect
The switch statement must use the variable
day to check its value.2fill in blank
mediumComplete the code to print Weekend when day is Saturday or Sunday.
Go
switch day {
case "Saturday", [1]:
println("Weekend")
default:
println("Weekday")
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using a weekday like Monday or Friday instead of Sunday.
Forgetting the quotes around the day names.
โ Incorrect
Saturday and Sunday are weekend days, so Sunday must be the second case value.
3fill in blank
hardFix the error in the switch statement to correctly print the message for day.
Go
switch day {
case "Monday":
println("Start of the week")
case [1]:
println("Midweek")
default:
println("Other day")
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Writing case value without quotes causing syntax error.
Using a wrong day name.
โ Incorrect
Case values must be strings with quotes, so
"Wednesday" is correct.4fill in blank
hardFill both blanks to create a switch that prints Early week for Monday or Tuesday.
Go
switch [1] { case [2]: println("Early week") default: println("Other day") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using wrong variable name in switch.
Using wrong days in case.
โ Incorrect
The switch must use
day and the case must include Monday and Tuesday.5fill in blank
hardFill all three blanks to create a switch that prints the correct message for score.
Go
switch {
case score [1] 90:
println("Excellent")
case score [2] 60:
println("Pass")
default:
println([3])
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Mixing up comparison operators.
Forgetting quotes around the string in default.
โ Incorrect
The first case checks if score is >= 90, second if score >= 60, and default prints "Fail".