0
0
Goprogramming~10 mins

Why operators are 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 add two numbers and print the result.

Go
package main
import "fmt"
func main() {
    sum := 5 [1] 3
    fmt.Println(sum)
}
Drag options to blanks, or click blank then click option'
A*
B-
C/
D+
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
2fill in blank
medium

Complete the code to check if a number is greater than 10.

Go
package main
import "fmt"
func main() {
    num := 15
    if num [1] 10 {
        fmt.Println("Number 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 less than or equal instead of greater than.
3fill in blank
hard

Fix the error in the code to multiply two numbers correctly.

Go
package main
import "fmt"
func main() {
    a := 4
    b := 5
    product := a [1] b
    fmt.Println(product)
}
Drag options to blanks, or click blank then click option'
A*
B-
C+
D/
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using addition or division instead of multiplication.
4fill in blank
hard

Fill both blanks to create a map of words and their lengths, including only words longer than 3 letters.

Go
package main
import "fmt"
func main() {
    words := []string{"go", "code", "fun", "learn"}
    lengths := map[string]int{
        [1]: len([2]),
    }
    fmt.Println(lengths)
}
Drag options to blanks, or click blank then click option'
A"code"
B"go"
Cwords[1]
Dwords[0]
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using the wrong index or mismatching key and value.
5fill in blank
hard

Fill all three blanks to create a map of words and their lengths, filtering words longer than 2 letters.

Go
package main
import "fmt"
func main() {
    words := []string{"go", "code", "fun", "learn"}
    lengths := map[string]int{}
    for _, word := range words {
        if len(word) [3] 2 {
            lengths[[1]] = [2]
        }
    }
    fmt.Println(lengths)
}
Drag options to blanks, or click blank then click option'
A"CODE"
Blen(word)
C>
Dword
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using wrong comparison operators or mismatching key and value.