Q:

Swift / how to get score increases by one each time when user get correct answer?

I am new to Swift. I'm currently learning structure module.
I was asked to create a score that increases 1 point each time the user gets an answer right, but my score ends up increased by 2. I am so confused. Everything else is fine. Can someone help me out please?
My code is below:
import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var questionLable: UILabel!
    @IBOutlet weak var progressBar: UIProgressView!
    @IBOutlet weak var trueButton: UIButton!
    @IBOutlet weak var falseButton: UIButton!
    @IBOutlet weak var scoreLabel: UILabel!

    var quizBrain = QuizBrain()

    override func viewDidLoad() {
        super.viewDidLoad()
        progressBar.progress = 0
        updatedUI()
    }

    @IBAction func answerButtonPressed(_ sender: UIButton) {

        let userAnswer = sender.currentTitle!        
        let userGotItRight = quizBrain.checkAnswer(userAnswer) 

        print(quizBrain.checkAnswer(userAnswer))
        if userGotItRight{              

            UIView.animate(withDuration: 0.2) {
                sender.backgroundColor = #colorLiteral(red: 0.4745098054, green: 0.8392156959, blue: 0.9764705896, alpha: 1)
            }
            UIView.animate(withDuration: 0.2) {
                sender.backgroundColor = UIColor.clear
            }
        }else{
            UIView.animate(withDuration: 0.2) {
                sender.backgroundColor = #colorLiteral(red: 0.9098039269, green: 0.4784313738, blue: 0.6431372762, alpha: 1)
            }
            UIView.animate(withDuration: 0.2) {
                sender.backgroundColor = UIColor.clear
            }
        }

        quizBrain.nextQuestion()
        updatedUI()
    }

    func updatedUI()  {
        questionLable.text = quizBrain.getQuestionText()
        scoreLabel.text = "Score:\(quizBrain.getScore())"
        progressBar.progress = quizBrain.getProgress()

    }
}

The next part is Model:
import Foundation

struct QuizBrain {
    let quiz = [

        Question(q: "A slug's blood is green.", a: "True"),
        Question(q: "Approximately one quarter of human bones are in the feet.", a: "True"),
        Question(q: "The total surface area of two human lungs is approximately 70 square metres.", a: "True"),
        Question(q: "Chocolate affects a dog's heart and nervous system; a few ounces are enough to kill a small dog.", a: "True")

    ]
    var questionNumber = 0
    var score = 0

    mutating func checkAnswer(_ userAnswer: String) -> Bool {
        if userAnswer == quiz[questionNumber].answer{     
            score += 1
            return true                 
        }else{
            return false
        }

    }
   mutating func getScore() -> Int {
        return score
    }
    func getQuestionText() -> String {

        return quiz[questionNumber].text     
    }
    func getProgress() -> Float {
        let progress = Float(questionNumber + 1)/Float(quiz.count)
        return progress
    }
    mutating func nextQuestion(){
        if questionNumber + 1 < quiz.count{           
           questionNumber += 1       
        }else {
            questionNumber = 0
            score = 0
        }
    }

}

A:

Your problem is in these two lines:
   let userGotItRight = quizBrain.checkAnswer(userAnswer) 

    print(quizBrain.checkAnswer(userAnswer))

In the first line, you check the answer to see if it is true.  If true, it increments by one, but in the next line, you want to just print the result, but you actually call the checkAnswer again, which increments it one more time.
Perhaps you could change the two lines to look like this:
let userGotItRight = quizBrain.checkAnswer(userAnswer) 
print(userGotItRight)

