Hi guys,
So I'm new to swift and I'm having some issues with the second challenge... I'm not sure how to fix it. I have written a if statement underneath the func buttontapped and used UIAlertController and UIAlertAction. But when I reach 10, it just continues to count from 10 to 11 and so on. And both the title and the message is not displayed. Also I am having issues with the second challenge as well. It's sort of works, but it doesn't display the correct country for the flag the sender has tapped.
This is my code:
var wrongAnswer = 0 var topScore = 0
@IBAction func buttonTapped(_ sender: UIButton) { var title: String
if sender.tag == correctAnswer {
title = "Correct"
score += 1
let ac = UIAlertController(title: title, message: "Your score is \(score)", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "Continue", style: .default, handler: askQuestion))
present(ac, animated: true)
} else {
title = "Wrong"
score -= 1
let aw = UIAlertController(title: title, message: "Wrong! That's the flag of \(countries[wrongAnswer])", preferredStyle: .alert)
aw.addAction(UIAlertAction(title: "Continue", style: .default, handler: askQuestion))
present(aw, animated: false)
}
if topScore == 10 {
let at = UIAlertController(title: "10 guesses done", message: "You have reached the end of this game, your final Score is \(score)", preferredStyle: .alert)
at.addAction(UIAlertAction(title: "Restart", style: .default, handler: askQuestion))
present(at, animated: true)
}
I would be very happy if someone could help me. :)