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
Fares Ksebati
7,426 PointsFun Facts app - for loop help
Hi all,
I am modifying the Fun Facts starter app a little bit. I'd like to pass through my array every time the button is pressed.
struct WorkoutBook {
let workoutArray = [
"500",
"600",
"800",
"300",
"Pull"
]
func doWork() -> String {
for workout in workoutArray {
return workout
}
}
1 Answer
kjvswift93
13,515 PointsFirst could you please elaborate just a bit more about what exactly are you trying to accomplish. Also your Array doesn't quite make sense to me (perhaps it might once you explained your intent in more detail), but it's possible that you would be better off using a dictionary as opposed to an array, however I still don't know what the program task is exactly so I can't be certain.
Fares Ksebati
7,426 PointsFares Ksebati
7,426 PointsHey Kyle, Thanks for the reply. I would like to display one index in the array (in order), every time the button is pressed. The example Fun Facts app uses the ark4random_uniform function. Instead of randomly iterating through the array, I would rather iterate through all the index in order. Please let me know if you need more clarification. Thanks, Fares