Lesson 8 Challenge (14 Day Code) Why is it not printing anything?

struct Car {

var make:String = "Toyota"
var model:String = "Camry"
var year:String = "1999"

var details:String {
    return year + make + model
}

func getDetails() {
    print(details)
    
}

}

1 Like

Welcome to the community!

You need to call your function!

You’re defining the function, saying what it does, but you’re never actually calling, or executing it.

Call it like this:
getDetails()

1 Like

Hi, You need to create an instance of the Struct after your Struct code declaration in order to utilise it. All is explained in Lesson 9.

// 1. after the last curly bracket, assign an instance of the Car() Struct to a var of type Car.
var myCar:Car = Car()

// 2. call the getDetails() Method from the Struct by using dot notation on your instance…
myCar.getDetails()

You will also need to edit your details computed property to include spaces e.g.
return year + " " + make + " " + model

1 Like