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 trial
Nils Garland
18,416 PointsWhats wrong?
This gives me an error, whats wrong ?
my code:
import Foundation
// This is my factbook where all the facts on the app are stored.
struct factBook {
let factArray = [
"Pteronophobia is the fear of being tickled by feathers!",
"In Sweden, it is illegal to name a child superman and ikea.",
"The average woman uses her height in lipstick every 5 years.",
"During your lifetime, you will produce enough saliva to fill two swimming pools.",
"If you consistently fart for 6 years & 9 months, enough gas is produced to create the energy of an atomic bomb!",
"King Henry VIII slept with a gigantic axe beside him.",
]
func randomFact() -> String{
var randomNumber = Int(arc4random_uniform(factArray.count))
}
}
1 Answer
Marina Alenskaja
9,320 PointsHi Nils
The problem is, that you are trying to convert the result to an Int when the type is actually UInt32. To fix this simply write UInt32 instead and write it after the arc4random function. Then keep the Int to convert the output to Int instead of the UInt32 like this:
struct factBook {
let factArray = [
"Pteronophobia is the fear of being tickled by feathers!",
"In Sweden, it is illegal to name a child superman and ikea.",
"The average woman uses her height in lipstick every 5 years.",
"During your lifetime, you will produce enough saliva to fill two swimming pools.",
"If you consistently fart for 6 years & 9 months, enough gas is produced to create the energy of an atomic bomb!",
"King Henry VIII slept with a gigantic axe beside him.",
]
func randomFact() -> String{
var randomNumber = Int(arc4random_uniform(UInt32(factArray.count)))
}
}
You will of course also need to add a return statement.
I hope that helps :-)
Nils Garland
18,416 PointsNils Garland
18,416 PointsThank's a lot really helps :D