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

iOS Swift Basics (retired) Control Flow Exercise: FizzBuzz Generator

Osiris Maldonado
Osiris Maldonado
699 Points

FizzBuzz: I want to add to my println function.

I am very very green, so apologies if this question is out of place.

I want to know how should I proceed if I want the println to not only print out the string: "FizzBuzz", "Fizz" or "Buzz", but also the number in question followed by the phrase. Something like:

3 is a Fizz

Other than that the exercise went smoothly, I used Switch instead of If-Then.

Thanks!

1 Answer

Chris Shaw
Chris Shaw
26,676 Points

Hi Osiris,

You can simply use interpolation for this which was discussed earlier on in the course, if you've created your code following the instructions to where i is your variable in your loop the below code should work perfectly, if you didn't use i you will need to replace that with your iterator variable.

println("\(i) is a Fizz")

Happy coding!

Osiris Maldonado
Osiris Maldonado
699 Points

Worked like a charm. Thank you, Chris!