0
0
Goprogramming~10 mins

Assignment operators 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 add 5 to variable x using an assignment operator.

Go
package main

import "fmt"

func main() {
    x := 10
    x [1] 5
    fmt.Println(x)
}
Drag options to blanks, or click blank then click option'
A/=
B-=
C*=
D+=
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '-' instead of '+' will subtract instead of add.
Using '*' or '/' will multiply or divide, not add.
2fill in blank
medium

Complete the code to multiply variable y by 3 using an assignment operator.

Go
package main

import "fmt"

func main() {
    y := 4
    y [1] 3
    fmt.Println(y)
}
Drag options to blanks, or click blank then click option'
A/=
B+=
C*=
D-=
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '+=' will add instead of multiply.
Using '-=' or '/=' will subtract or divide, not multiply.
3fill in blank
hard

Fix the error in the code by choosing the correct assignment operator to subtract 2 from z.

Go
package main

import "fmt"

func main() {
    z := 15
    z [1] 2
    fmt.Println(z)
}
Drag options to blanks, or click blank then click option'
A+=
B-=
C*=
D/=
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '+=' will add instead of subtract.
Using '*=' or '/=' will multiply or divide, not subtract.
4fill in blank
hard

Fill both blanks to divide variable a by 4 and assign the result back, then print it.

Go
package main

import "fmt"

func main() {
    a := 20
    a [1] 4
    fmt.[2](a)
}
Drag options to blanks, or click blank then click option'
A/=
BPrintln
CPrintf
D+=
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '+=' instead of '/=' will add instead of divide.
Using Printf without formatting string causes error.
5fill in blank
hard

Fill all three blanks to create a map with keys as uppercase letters and values as their squares, only for numbers greater than 3.

Go
package main

import "fmt"

func main() {
    nums := []int{1, 2, 3, 4, 5}
    squares := map[string]int{}
    for _, n := range nums {
        if n [3] 3 {
            squares[[1]] = [2]
        }
    }
    fmt.Println(squares)
}
Drag options to blanks, or click blank then click option'
Astring(rune(n + 64))
Bn * n
C>
Dn + n
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '+' instead of '*' for squaring.
Using '<' instead of '>' for filtering.
Not converting number to string for map keys.