|
On Project 5, WordScramble, and I'm trying to do Challenge #3. Here is the code for my textField |
|
Call a function that itself calls FYI, you can format your code using three backticks
See how much nicer and easier to read that is? |
|
Thanks, that does look better. Putting the 2 func in a single func worked. But now, my else statement isn't working. It increases score by one no matter what. Also, it is increasing score even if an error message comes up. How do I say increase score unless all of the error func's don't come up?
|
![]() SAVE 50% To celebrate Black Friday, 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. Sponsor Hacking with Swift and reach the world's largest Swift community! |
|
Thanks, that does look better. Putting the 2 func in a single func worked. But now, my else statement isn't working. It increases score by one no matter what. Also, it is increasing score even if an error message comes up. How do I say increase score unless all of the error func's don't come up?
|
|
Your issue is not "where you declare" the function, just keep it at the same level as the other functions. The answer is "where do you use it". Essentially you should call the function near the end of Hope that helps. |
|
1: I put increaseScore at the end of all of the guard func, and the else statement is working, but it still increases even if there is an error.2: How can I refresh the app when I hit the Restart button? right now it just gives a new word
|
|
Here you call But also... Inside the |
|
As per the previous comment, you don't need the As for the restart, it should give you a new word at the top and an empty list... all the button should technically do is reset the usedWords array, and startNewGame(). |
|
How do I reset the usedWords array? I've tried usedWords[] and usedWords[]() in my Button (action:, but I keep getting an error |
|
Also, my else statement is still not working
|
|
Have your button call |
|
Ok. Thank you. That totally worked. How about the If ... else statement? It only increase by 1 no matter the word length. |
|
Word length is not being scored by you. You are simply adding the score based on the number of words. If the total words is less or equal to 5 you add 1, otherwise you add (Total number of words - 2)... Your else statement will only work starting with the 6th word you find. |
|
Ok. I changed usedWords to wordLength.
but when I call increaseScore
i get an error "Missing argument for parameter 'word' in call" |
|
Right, because your So you have to supply a |
|
would that be in the func increaseScore()? or would that be when I call increaseScore()? also, I don't have an "answer" variable. would that be usedWords? |
|
That would be when you call I was basing what I wrote on the fact that you are currently (at least the last time you posted significant code) calling |
|
You were right, I just totally looked over it . Adding (word: answer) totally worked, and now the app works exactly how I want. thank you so much for taking the time to help. |
SAVE 50% To celebrate Black Friday, 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.
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.