|
Can anyone help me with my code for Checkpoint 4? Swift is telling me I need to include a return in my function, but I already have one. Do I have it in the wrong place? What else have I done wrong? Appreciate any advice. Andrew |
|
Hint 1: Hint 2:
Hint 3: Hint 4: Number may not be a good name for your variable. Swift actually has a class named Refactor your code, you might get better results! If not repost your code here, using the code tags, of course. |
|
Thanks for your reply @Obelix. Here's my revised code.
It now works, but I'm still left with my original question. Why did I have to return a blank string (or any other string for that matter) to get it to work when I was already returning a string in the if? Grateful for any response. Andrew |
|
Andrew is asking the right questions! He asked:
Return Type is StringYou declared your function must return a What gets returned here if girlfriend's age is 42?
Answer is nothing is returned. So the compiler will complain. To fix, you might return a blank string?
In short, none of your |
|
RefactoringTake a look at this section of code:
|
|
Naming Variables+1 for updating variable names. But you missed an opportunity. Your user wants to find the square root of some number. Let's call that: See if this is clearer to future you?
Get in the habit of using descriptive variable names. XCode's code completion helps you, because you won't have to type out long names; it will do that for you. But future you will appreciate you using descriptive names. CS193p MemorizeIf you have a look at Paul Hagerty's Swift course at Stanford University (CS193p), in his lecture for his card matching game he creates an index named: The whole series is excellent and adds perspective to @twostraws' excellent lectures. For convenience, here's the part where CS193p talks about descriptive variable names. Jump to 01:12:00 > Memorize Game Logic |
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!
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.
Link copied to your pasteboard.