Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a struct named Person.
Go
type [1] struct {
Name string
Age int
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase struct names which are unexported.
Using reserved words like Struct.
✗ Incorrect
The struct name should start with a capital letter to be exported. Here, Person is the correct struct name.
2fill in blank
mediumComplete the code to create a variable of type Person.
Go
var p [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using basic types like int or string instead of the struct name.
Using the keyword struct directly.
✗ Incorrect
To create a variable of the struct type, use the struct's name Person.
3fill in blank
hardFix the error in the struct field definition.
Go
type Car struct {
Brand [1]
Year int
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using capitalized types like String.
Using non-existent types like str.
✗ Incorrect
In Go, the correct type for text is string (all lowercase).
4fill in blank
hardFill both blanks to define a struct with two fields.
Go
type Book struct {
Title [1]
Pages [2]
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using float64 for Pages which should be an integer.
Using bool for text fields.
✗ Incorrect
The Title should be a string and Pages should be an int because pages are whole numbers.
5fill in blank
hardFill all three blanks to define a struct and create a variable of that struct.
Go
type [1] struct { Name string Age [2] } var p [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatch between struct name and variable type.
Using string for Age instead of int.
✗ Incorrect
The struct is named Person, Age is an int, and the variable p is of type Person.