Course Content
Introduction to GoLang
Introduction to GoLang
Challenge: Creating a Structure
Task
Create a structure named Car
with fields company
, owner
, miles
, and year
in the same order. Assign appropriate data types to them based on the provided code.
index.go
Create a structure called
Car
with fields
company
, owner
, miles
and
year
in the same order, and assign appropriate data types to them
based on the given code.
package main
import "fmt"
// Write code below this line
type Car struct {
company string
owner string
miles float32
year int
}
// Write code above this line
func main() {
var car1 Car
car1.company = "Tesla"
car1.owner = "Tegmark"
car1.miles = 10.7
car1.year = 2021
fmt.Println(car1)
}
Everything was clear?
Section 6. Chapter 8
Course Content
Introduction to GoLang
Introduction to GoLang
Challenge: Creating a Structure
Task
Create a structure named Car
with fields company
, owner
, miles
, and year
in the same order. Assign appropriate data types to them based on the provided code.
index.go
Create a structure called
Car
with fields
company
, owner
, miles
and
year
in the same order, and assign appropriate data types to them
based on the given code.
package main
import "fmt"
// Write code below this line
type Car struct {
company string
owner string
miles float32
year int
}
// Write code above this line
func main() {
var car1 Car
car1.company = "Tesla"
car1.owner = "Tegmark"
car1.miles = 10.7
car1.year = 2021
fmt.Println(car1)
}
Everything was clear?
Section 6. Chapter 8