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 trialboris said
3,607 PointsXcode is making me change vars to constant and it doesn't run when they are constants
I have tried it with the cryptic and readable version-both fails and when they are changed to constants it fails upon starting. Here is my code:
struct FactBook {
let factsArray = [
"Ants stretch when they wake up in the morning.",
"Ostriches can run faster than horses.",
"Olympic gold medals are actually made mostly of silver.",
"You are born with 300 bones; by the time you are an adult you will have 206.",
"It takes about 8 minutes for light from the Sun to reach Earth.",
"Some bamboo plants can grow almost a meter in just one day.",
"The state of Florida is bigger than England.",
"Some penguins can leap 2-3 meters out of the water.",
"On average, it takes 66 days to form a new habit.",
"Mammoths still walked the earth when the Great Pyramid was being built." ]
func randomFact()->String {
var randomNumber = Int(arc4random_uniform(UInt32(10)))
return factsArray[randomNumber]
}
2 Answers
Matthew Young
5,133 PointsXcode suggests when to change variables to constants because it makes your code safer. If a value doesn't have to change, there's no reason leaving it as a variable.
I believe the main issue with your code is that you're missing an additional closing curly brace at the bottom to close off your FactBook struct.
boris said
3,607 PointsThanks a lot. You've fixed it!