0
0
Goprogramming~10 mins

Type inference 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 a variable with type inference.

Go
var x = [1]
Drag options to blanks, or click blank then click option'
Avar
Bint
C"Hello, Go!"
Dstring
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a type name instead of a value after the equals sign.
Trying to declare type explicitly when using type inference.
2fill in blank
medium

Complete the code to declare and initialize a variable using short variable declaration with type inference.

Go
count [1] 10
Drag options to blanks, or click blank then click option'
A==
B=
Cvar
D:=
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using single equals sign which is assignment, not declaration.
Using double equals which is a comparison operator.
3fill in blank
hard

Fix the error in the code by completing the variable declaration with type inference.

Go
var pi [1] 3.14
Drag options to blanks, or click blank then click option'
A=
B:=
Cfloat64
D==
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using := with var keyword causes syntax error.
Using == which is a comparison operator.
4fill in blank
hard

Fill both blanks to declare a variable with type inference and assign a boolean value.

Go
isReady [1] [2]
Drag options to blanks, or click blank then click option'
A:=
Btrue
Cfalse
D=
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using = instead of := for declaration.
Using false instead of true if the goal is to assign true.
5fill in blank
hard

Fill both blanks to create a map with type inference and initialize it with values.

Go
scores := map[string]int{"Alice": {BLANK_2}}, "Bob": {{BLANK_2}}
Drag options to blanks, or click blank then click option'
A{
B90
C85
D}
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Omitting the opening or closing curly braces.
Using string values instead of integers for scores.