dimanche 28 février 2016

if Statements calling on random array

This is the code i have made so far. I have two words, red and black. when the red button is pressed i want an if statement that tells the user if they are wrong or right. The code picks randomly either red or black but i can't seem to figure how to match the if statement with word that is randomly picked.

@IBAction func red(sender: AnyObject) {

    let array = ["Red", "Black"]
    let randomIndex = Int(arc4random_uniform(UInt32(array.count)))
    print(array[randomIndex])


    if array == Int("Red") {

        colorLabel.text = "You're right"


    } else {

        colorLabel.text = "Wrong! It was a Black"
    }



}

Aucun commentaire:

Enregistrer un commentaire