|
Hello to you all, In checkpoint 4 I managed to solve the solution after much thinking, looking for missing pieces of information in past lectures and even googling (in other languages). I came up with a solution that seems too verbose especially after seeing the solution from Paul Hudson. Code:
Something in my brain tells me this is just a bad solution, too much clutter. I used else ifs but paul just used two if statements, I made a variable to hold a value of "0" and then inside the for loop I made another variable that held the expression "i * i" to later then use it, You get the idea I hope that I did "too much" was this wrong? What could I have changed in my code to make it better, without just simply copy pasting Paul's solution? Thank you for taking the time to read this, I look forward to your answers! |
|
Great job(ish). You're understanding the mnemonics. That's a great thing! The logic part maybe not so much. In Engineering the best way to approach a subject is take a large problem and break it down into smaller problems. You'll hear that a lot.... Let's look at one of the smaller parts you have written.....
If you stand back and really think about what you are actually doing here then you'll probably think oh bloody hell, what was I thinking?..... If not let's look at what you're actually doing. You are executing a for loop.....
Meaning this part and everything in the loop will loop 10000 times.....
Meaning you are checking that your firstNum is less than 1 or greater than 10000..... That's great and all, but you are checking it/the same thing ten thousand times, where you should only need to check it once before you return the verdict. How to correct that.....I think you'll figure it out now that you have direction. I would not dwell on this too much though...If at all, because through the course and doing more of logic and code you'll get a lot better and if you actually "return" pardon the the pun! To some of these starter checkpoints later on you will be doing them with your eyes closed. Lastly make sure you use a catch all errors so that you can give the user a pleasant message. I often think about putting in a mission impossible theme tune when that happens, but that's just me/my preference. A picture of a fluffy white dog with an "Oops no treats for you" message might be good thing as well. Keep going you'll do great! |
|
Some notes...
|
|
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.