@Frederick may have lost track of his logic!
Am I the only one that experience this problem, or is it someting in my code, that is wrong?
Sometimes it's worthwhile to grab a pencil and a scrap of paper and write down the steps you're giving to your compiler.
From your code above...
func newGame() {
questionCounter = 0 // 1. Reset the counter
score = 0 // 2. Reset the score
countries = Self.allCountries // 3. Grab a fresh copy of ALL the countries
askQuestion()
}
func askQuestion() {
countries.remove(at: correctAnswer) // 4. Remove the country at position correctAnswer
countries.shuffle() // 5. Shuffle the remaining countries
correctAnswer = Int.random(in: 0...2) // 6. Pick one of the first three countries
questionCounter += 1 // 7. something
}
Your logic:
- Previous game's correct answer was New Zealand in array position 1. (This is an example.)
- Reset the game's question counter to zero.
- Reset the game's score to zero.
- Grab a fresh copy of ALL the countries.
- Remove the country at position 1. (From step 0)
- Shuffle the remaining countries.
- Pick one of the first three countries.
For illustration purposes, let's assume in the previous game that you shuffled the array and that New Zealand was in position #1 and was selected as the correct answer.
Please note Step 3! When you get a FRESH copy of ALL your countries, where is New Zealand in this copy? Can you be sure that it's in the first position?
Then in Step 4, you REMOVE whatever country is in position #1. (It might be Greenland! or Madagascar!)
Back to the Drawing Board
I didn't answer your question directly. But this should put you on the right path to restructuring your logic.