I've tried to make an if else statement for a game similar to the high/low game. when you click the button, it seems like the statement is skipping over the 'if NewNumber <= oldNumber part and just going straight to the else part. It should check the new integer against the old one and see if its higher or lower.. Only been doing swift for a little while so I'm not sure what I'm doing wrong
//Lower Button
@IBAction func lowerButton(sender: AnyObject) {
var newNumber = randomIntBetween(2, high: 26)
var oldNumber: Int?
func lowerNumber() -> Int {
if newNumber <= oldNumber {
correctWrongLabel.text = "You Were Correct!"
scoreLabel.text = "Score: \(countWin++)"
} else {
correctWrongLabel.text = "You Were Wrong!"
scoreLabel.text = "Score: \(countLose)"
}
return newNumber
}
let newValue = lowerNumber()
randomIntLabel.text = "\(newValue)"
}
Aucun commentaire:
Enregistrer un commentaire