Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using < instead of >
Using == which checks equality, not greater than
โ Incorrect
The greater than operator > checks if x is more than 10.
2fill in blank
mediumComplete 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using + or - instead of %
Using * which multiplies numbers
โ Incorrect
The modulus operator % gives the remainder. If remainder is 0 when divided by 2, the number is even.
3fill in blank
hardFix 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using < or <= which check less than
Using == which checks exact equality
โ Incorrect
The operator >= means 'greater than or equal to', so it checks if age is 18 or more.
4fill in blank
hardFill 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using > or < which exclude boundary values
Mixing up the order of operators
โ Incorrect
The condition checks if score is at least 50 (>=) and at most 100 (<=).
5fill in blank
hardFill 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using different variable names inconsistently
Using wrong expressions for length
โ Incorrect
The map uses the word as key and its length as value. The loop variable is word.