Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using var keyword with := operator causes syntax error.
Trying to declare type explicitly with short declaration is invalid.
โ Incorrect
In Go, short variable declaration uses the syntax
name := value. So x := 10 declares and initializes x with 10.2fill in blank
mediumComplete 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using parentheses or brackets around variable names is invalid.
Using var keyword with := causes syntax error.
โ Incorrect
To declare multiple variables with short declaration, list their names separated by commas before :=.
3fill in blank
hardFix 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using var keyword with := causes syntax error.
Using = instead of := for short declaration.
โ Incorrect
Short variable declaration uses := without var keyword. So
count := 100 is correct.4fill in blank
hardFill 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Trying to declare both variables in one statement with commas.
Using var keyword with := operator.
โ Incorrect
Each variable must be declared separately with short declaration syntax:
name := "Alice" and age := 30.5fill in blank
hardFill 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using wrong variable names in declaration.
Trying to declare multiple variables in one line incorrectly.
โ Incorrect
Declare
width and height with short declaration, then declare area as their product.