dimanche 1 mai 2016

Why won't swift recalculate the 'if' statement?

I'm trying to create a very simple 'guessing game' where the user has to guess how many fingers the computer has up (maximum 5 fingers).

Here's the thing. When the code executes and I press submit, even when the print logs registers a correct number, the app still prints the if statement for incorrect. Where am I going wrong?

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}




@IBOutlet weak var fingerInput: UITextField!

@IBOutlet weak var fingerResult: UILabel!

@IBAction func fingerSubmit(sender: AnyObject) {

    let realNumberofFingers = Int(arc4random_uniform(6))

    print(realNumberofFingers)

    if fingerInput != realNumberofFingers {

        fingerResult.text = "Gosh darn, that's wrong!"

    } else if fingerInput == realNumberofFingers {

        fingerResult.text = "Thats right!"

    }
}

}

Aucun commentaire:

Enregistrer un commentaire