0
0
Goprogramming~10 mins

Short variable declaration 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 declare and initialize variable x with value 10 using short variable declaration.

Go
func main() {
    [1] := 10
    fmt.Println(x)
}
Drag options to blanks, or click blank then click option'
Avar x
Bx
Cint x
Dx var
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using var keyword with := operator causes syntax error.
Trying to declare type explicitly with short declaration is invalid.
2fill in blank
medium

Complete the code to declare two variables a and b with values 5 and 7 using short variable declaration.

Go
func main() {
    [1] := 5, 7
    fmt.Println(a, b)
}
Drag options to blanks, or click blank then click option'
A(a, b)
Bvar a, b
Ca, b
D[a, b]
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using parentheses or brackets around variable names is invalid.
Using var keyword with := causes syntax error.
3fill in blank
hard

Fix the error in the short variable declaration of count with value 100.

Go
func main() {
    [1] 100
    fmt.Println(count)
}
Drag options to blanks, or click blank then click option'
Avar count =
Bvar count :=
Ccount :
Dcount :=
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using var keyword with := causes syntax error.
Using = instead of := for short declaration.
4fill in blank
hard

Fill both blanks to declare variables name and age with values "Alice" and 30 using short variable declaration.

Go
func main() {
    [1] := "Alice"
    [2] := 30
    fmt.Println(name, age)
}
Drag options to blanks, or click blank then click option'
Aname
Bage
Cvar
Dint
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Trying to declare both variables in one statement with commas.
Using var keyword with := operator.
5fill in blank
hard

Fill all three blanks to declare variables width, height, and area where width and height are 5 and 10, and area is their product using short variable declaration.

Go
func main() {
    [1] := 5
    [2] := 10
    [3] := [1] * [2]
    fmt.Println(area)
}
Drag options to blanks, or click blank then click option'
Awidth
Bheight
Carea
Dsize
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using wrong variable names in declaration.
Trying to declare multiple variables in one line incorrectly.