Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialmathisvaneetvelde
9,366 PointsStrings and arrays
I don't know whats wrong with my code. Can anyone solve this ?
This is what te console said: The favoriteSports
variable was expected to be a array of strings (aka [String]
), but it wasn't.
let bestSmartphone = "iPhone"
var favoriteSports: String = "football"
3 Answers
kjvswift93
13,515 PointsIt should look like this:
let bestSmartphone = "iPhone"
var favoriteSports = ["football", "basketball", "tennis"]
favoriteSports.append("volleyball")
Marlon Henry
6,885 Pointslet bestSmartphone = "iPhone"
var favoriteSports = ["football", "basketball", "baseball"]
An array is encased in []
What you wrote is:
var favoriteSports: String = "football"
This just means that you want favorite sports array to be a explicative type of string with the value being football. In english what you said is "My favorite sports are football." Hope this helps.
David Maybach
2,092 PointsI was doing this:
var favoriteSports = ["football","basketball","tennis"]
println ("\(favoriteSports), volleyball")
Marlon Henry
6,885 PointsYeah that works, it will add volleyball to the array, but why not .append it to the array(well mutable array)?
mathisvaneetvelde
9,366 Pointsmathisvaneetvelde
9,366 PointsThank you verry much !