0
0
Goprogramming~10 mins

Switch statement in Go - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
ADay
Bdays
Cday
DweekDay
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.
2fill in blank
medium

Complete 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'
A"Monday"
B"Sunday"
C"Friday"
D"Tuesday"
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a weekday like Monday or Friday instead of Sunday.
Forgetting the quotes around the day names.
3fill in blank
hard

Fix 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'
AWednesday
B"Tuesday"
C"Friday"
D"Wednesday"
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Writing case value without quotes causing syntax error.
Using a wrong day name.
4fill in blank
hard

Fill 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'
Aday
B"Monday", "Tuesday"
C"Wednesday", "Thursday"
Dweekday
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using wrong variable name in switch.
Using wrong days in case.
5fill in blank
hard

Fill 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'
A>=
C"Fail"
D<
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Mixing up comparison operators.
Forgetting quotes around the string in default.