What I am asking if this is correct. If not, why?
Or is there something missing. I’m super new to coding, so dumbing things down low will help me a lot. Im eager to learn but again, im super new to coding.
Declare 4 properties called make , model , year and details
Assign String data to the make , model and year properties (use whatever values you want)
Make the details property a computed property that returns a String with the year , make and model . (For example, “1999 Toyota Camry”)
(Hint: You can use the + operator to add strings together. This is also known as concatenation)
Make all 4 properties have the private access level
Finally, declare a method called getDetails which returns the value of the details property.
Declare a struct called Car
struct Car {
}
Declare 4 properties called make , model , year and details
Assign String data to the make , model and year properties (use whatever values you want)
Make the details property a computed property that returns a String with the year , make and model . (For example, “1999 Toyota Camry”)
Make all 4 properties have the private access level
struct Car {
private let make: String = "Toyota"
private let model: String = "Yaris"
private let year: String = "2020"
private var details: String {
return "\(year) \(make) \(model)"
}
}
Finally, declare a method called getDetails which returns the value of the details property.
truct Car {
private let make: String = "Toyota"
private let model: String = "Yaris"
private let year: String = "2020"
private var details: String {
return year + " " + make + " " + model
// you could also say
// return "\(year) \(make) \(model)" which uses string interpolation
}
func getDetails() -> String {
return details
}
}
Also how did you know to set it up that way? I obviously read the question wrong. The way I set it up some far from right. Like I said I’m super new to coding.
How did you know to use a constant rather than a variable? That’s what I been using. I think were I am getting confused is Qs 4 and 5, especially #5-private access level. I took a break and relooked at this challenge and it still through me off.
You can also use let by default in case you’re confused @osvaldotl. That’s a small technique I learned by reading the document created by Apple. The same document that sometimes gives me headaches