Updated for Xcode 13.3
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 Spend less time managing in-app purchase infrastructure so you can focus on building your app. RevenueCat gives everything you need to easily implement, manage, and analyze in-app purchases and subscriptions without managing servers or writing backend code.
Link copied to your pasteboard.