Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a struct named Person.
Go
type Person [1] {
Name string
Age int
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'class' instead of 'struct' because Go does not have classes.
Using 'interface' which is for behavior, not data grouping.
✗ Incorrect
In Go, struct is used to define a new data type that groups fields.
2fill in blank
mediumComplete the code to create a variable of type Person.
Go
var p [1] Person Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' without declaration.
Using 'var' keyword incorrectly here.
✗ Incorrect
The short declaration operator := is used to declare and initialize variables in Go.
3fill in blank
hardFix the error in the code to access the Age field of a Person struct.
Go
fmt.Println(p[1]Age) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '->' which is from other languages like C.
Using '::' or '#' which are invalid in Go for field access.
✗ Incorrect
In Go, the dot . operator is used to access fields of a struct.
4fill in blank
hardComplete the code to create a struct literal for Person with Name "Alice" and Age 30.
Go
p := Person{Name: "Alice", [1]: 30} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets instead of braces.
Omitting the field name for the second value.
✗ Incorrect
Struct literals use curly braces {} and field names to assign values.
5fill in blank
hardFill all three blanks to define a struct, create a variable, and assign a value.
Go
type [1] struct { Name string } var p [2] [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable name as the type.
Not assigning a struct literal when declaring the variable.
✗ Incorrect
First, define the struct type. Then declare a variable of that type and assign a struct literal.