0
0
Goprogramming~10 mins

Why conditional logic is needed in Go - Test Your Understanding

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

Complete the code to print "Adult" if age is 18 or more.

Go
if age [1] 18 {
    fmt.Println("Adult")
}
Drag options to blanks, or click blank then click option'
A!=
B<
C==
D>=
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '<' instead of '>=' will check the wrong condition.
Using '==' only checks if age is exactly 18, not more.
2fill in blank
medium

Complete the code to print "Even" if the number is divisible by 2.

Go
if num [1] 2 == 0 {
    fmt.Println("Even")
}
Drag options to blanks, or click blank then click option'
A*
B/
C%
D-
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '/' divides the number but does not check remainder.
Using '*' or '-' does not help check evenness.
3fill in blank
hard

Fix the error in the condition to check if score is less than 50.

Go
if score [1] 50 {
    fmt.Println("Fail")
}
Drag options to blanks, or click blank then click option'
A<
B==
C>
D>=
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '>' checks if score is greater than 50, which is opposite.
Using '==' checks equality, not less than.
4fill in blank
hard

Fill both blanks to print "Teenager" if age is between 13 and 19 inclusive.

Go
if age [1] 13 && age [2] 19 {
    fmt.Println("Teenager")
}
Drag options to blanks, or click blank then click option'
A>=
B<
C<=
D>
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '<' instead of '<=' excludes 19.
Using '>' instead of '>=' excludes 13.
5fill in blank
hard

Fill all three blanks to create a map of words to their lengths for words longer than 3 characters.

Go
lengths := make(map[string]int)
for _, [3] := range words {
    if len([3]) > 3 {
        lengths[[1]] = [2]
    }
}
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Dw
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using different variable names inconsistently.
Using the wrong expression for the length.