0
0
Goprogramming~10 mins

If 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 check if x is greater than 10.

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

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

Go
if number [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 + or - instead of %
Using * which multiplies numbers
3fill in blank
hard

Fix the error in the if statement to check if age is at least 18.

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 < or <= which check less than
Using == which checks exact equality
4fill in blank
hard

Fill both blanks to print "Valid" if score is between 50 and 100 inclusive.

Go
if score [1] 50 && score [2] 100 {
    fmt.Println("Valid")
}
Drag options to blanks, or click blank then click option'
A>=
B<
C<=
D>
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using > or < which exclude boundary values
Mixing up the order of operators
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 := 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 wrong expressions for length