Updated for Xcode 14.1
Now that you’re able to use conditions and loops, I’d like you to try a classic computer science problem. It’s not hard to understand, but it might take you a little time to solve depending on your prior experience!
The problem is called fizz buzz, and has been used in job interviews, university entrance tests, and more for as long as I can remember. Your goal is to loop from 1 through 100, and for each number:
So, here are some example values you should have when your code runs:
Before you start: This problem seems extremely simple, but many, many developers struggle to solve it. I’ve seen it happen personally, so don’t stress about it – just trying to solve the problem already teaches you about it.
You already know everything you need to solve that problem, but if you’d like some hints then I’ll add some below.
Please go ahead and try building the playground now.
Hacking with Swift+ subscribers can get a complete video solution for this checkpoint here: Solution to Checkpoint 3. If you don’t already subscribe, you can start a free trial today.
Still here? Okay, here are some hints:
.isMultiple(of:). For example,
elseblock to handle all other numbers.
&&to check for numbers that are multiples of 3 and 5, or have a nested
SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.
Link copied to your pasteboard.