Checkpoint 4 Solution

 Feb '22 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. Feb '22 You might want to look at this post Need some help with Checkpoint 4 Feb '22 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. Feb '22 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. Feb '22 Hey thanks for the insights guys!

SPONSORED Let’s face it, SwiftUI previews are limited, slow, and painful. Judo takes a different approach to building visually—think Interface Builder for SwiftUI. Build your interface in a completely visual canvas, then drag and drop into your Xcode project and wire up button clicks to custom code. Download the Mac App and start your free trial today!

Sponsor Hacking with Swift and reach the world's largest Swift community!

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.

You are not logged in

Link copied to your pasteboard.