0
0
Goprogramming~10 mins

Defining structs 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 define a struct named Person.

Go
type [1] struct {
    Name string
    Age  int
}
Drag options to blanks, or click blank then click option'
AData
Bperson
CStruct
DPerson
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase struct names which are unexported.
Using reserved words like Struct.
2fill in blank
medium

Complete the code to create a variable of type Person.

Go
var p [1]
Drag options to blanks, or click blank then click option'
Astruct
Bint
CPerson
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using basic types like int or string instead of the struct name.
Using the keyword struct directly.
3fill in blank
hard

Fix 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'
Astring
Bint
Cstr
DString
Attempts:
3 left
💡 Hint
Common Mistakes
Using capitalized types like String.
Using non-existent types like str.
4fill in blank
hard

Fill 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'
Astring
Bint
Cfloat64
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using float64 for Pages which should be an integer.
Using bool for text fields.
5fill in blank
hard

Fill 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'
APerson
Bint
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatch between struct name and variable type.
Using string for Age instead of int.