Hi!
I’m wondering why leftScore and rightScore don’t get initialized in the lesson 10 tutorial for the war card game. When I don’t initialize them my XCode yells at me, but it doesn’t look like Chris initialized them anywhere?
Here’s my code:
class ViewController: UIViewController {
@IBOutlet weak var leftImageView: UIImageView!
@IBOutlet weak var rightImageView: UIImageView!
@IBOutlet weak var leftScoreLabel: UILabel!
@IBOutlet weak var rightScoreLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func DealButtonView(_ sender: Any) {
print("Deal Tapped")
let leftNum = Int.random(in: 2...14)
let rightNum = Int.random(in:2...14)
leftImageView.image = UIImage(named: "card\(leftNum)")
rightImageView.image = UIImage(named: "card\(rightNum)")
if rightNum > leftNum {
rightScore += 1
rightScoreLabel.text = String(rightScore)
} else if leftNum > rightNum{
leftScore += 1
leftScoreLabel.text = String(leftScore)
} else{
//do nothing
}
}
If this forum isn’t the right place for this question let me know, and I’ll put it somewhere else