GAME: How Many Cats Do I Have?

Cat photographed by and copyright of (c) David Corby (User:Miskatonic, uploader) 2006

Hi!

Here’s the code for this game I created!

 

import UIKit

class ViewController: UIViewController {

    

    @IBOutlet weak var textField: UITextField!

    

    @IBOutlet weak var resultLabel: UILabel!

    @IBAction func guessNowBtn(_ sender: Any) {

        let randomNumber = String (arc4random_uniform(11))

        if textField.text == randomNumber {

            resultLabel.text = "You are right!"

        } else {

            resultLabel.text = "You are wrong! The correct number is " + randomNumber + "."

        }

    }

    

    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.

    }

}

 

 

Happy coding, my friends!

M