WWDC24 SALE: Save 50% on all my Swift books and bundles! >>

Checkpoint 4 Solution

Forums > 100 Days of SwiftUI

I'm confused why we would want to run the loop 100 times if it doesn't need to.

For example, if the square root we are looking for is 15 (there is no perfect square number that will get us to 15) why would we continue to run the loop after that.

I did an exhaustive loop (1...) and returned i if i multipied by i == number but then I also did an else if check to see if i multipled by i was greater than number, and if so, to break from the loop.

I feel like this incorporates more of what we learned and should be the actual solution instead of hardcoding in values.

Some feedback too while I am here... I wish the tests in each lesson would focus more on what I've learned in that lesson and not try to trick me with silly typo errors here and there as that's not helping to solidify understanding in that particular lesson in my opinion...

Edit: Also thank you for this course I'm not trying to be ungrateful I just want to point out my feedback.

2      

You might want to look at this post Need some help with Checkpoint 4

2      

gthang writes:

I wish the tests in each lesson would focus more on what I've learned in that lesson and not try to trick me with silly typo errors here and there as that's not helping to solidify understanding in that particular lesson

Maybe before your time? Do you remember the scene in the movie "The Karate Kid" where Mr Miyagi offers to teach Daniel LaRusso karate? But first Daniel must wash and wax the car? He had to "wax-on wax-off" 1000 times? Next he had to paint the fence. "Brush up, brush down" all day long, several thousands of times.

Daniel waxed and waxed. Then he painted and painted some more. Then he threw a fit, demanding to know when he would start learning karate and stop with the personal chores! You remember this scene?

Of course the reveal is that Mr Miyagi was teaching him moves and getting them ingrained in muscle memory. Wax-on, Wax-off is a defensive move. Very important to learning karate.

Catching "silly typo errors here and there" is Hacking With Swift's version of "Wax-On, Wax-Off".

You need this skill! You will be doing this tens of thousands of times on your 100 day journey. This skill is just as important as learning feature sets.

2      

gthang points out:

I'm confused why we would want to run the loop 100 times if it doesn't need to. I did an exhaustive loop (1...) and returned i if i multipied by i == number but then I also did an else if check to see if i multipled by i was greater than number, and if so, to break from the loop.

You have advanced insight into problem solving. Nice! This will help you later on.

The point of earlier lessons isn't focused so much on writing precise, tight, perfect code. It's about learning concepts.

You'll see this in later episodes, too. @twostraws will walk you down a design path full of nice working code. Then, BAM!, he'll erase a 10 line method you meticulously copied line by line and show, instead, a one line version producing the same results. You may ask why he didn't start with the one-line solution?

This is because it's good practice to use your brain to think through the multiple steps to solve a logic problem. Then work through the steps to reduce the complexity. Then, finally, using a newly introduced feature to accomplish the same task with one line of code.

2      

Hey thanks for the insights guys!

2      

Save 50% in my WWDC sale.

SAVE 50% To celebrate WWDC24, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.