// // ViewController.swift // PracticeMath import UIKit class ViewController: UIViewController { // FINISH ME // define (create) a variable // called num1 and set it to 0 ???? // FINISH ME // define (create) a variable // called num2 and set it to 0 ???? // number range 0 - max-1 var num1Max = 20 var num2Max = 10 // FINISH ME // link Number1 Label to this variable // increase the Font Size // set the Alignment to Right Justified // set the background color @IBOutlet weak var num1Label: UILabel! // FINISH ME // link Number2 Label to this variable // increase the Font Size // set the Alignment to Right Justified // set the background color @IBOutlet weak var num2Label: UILabel! // FINISH ME // link Op Label to this variable // increase the Font Size // set the Alignment to Right Justified // set the background color @IBOutlet weak var opLabel: UILabel! // FINISH ME // link Answer TextField to this variable // increase the Font Size // set the Border Style // set the Alignment to Right Justified // set the placeholder to answer @IBOutlet weak var userAnswerTextField: UITextField! // FINISH ME // link Correct/Incorrect Label to this variable // increase the Font Size // set the Border Style // set the Alignment to Centered // set the text color to your preference @IBOutlet weak var correctIncorrectLabel: UILabel! // FINISH ME // link to first Range label // increase the Font Size @IBOutlet weak var num1RangeLabel: UILabel! // FINISH ME // link to second Range label // increase the Font Size @IBOutlet weak var num2RangeLabel: UILabel! // this function sets the text on num1RangeLabel to show the Range 0-? @IBAction func slider(_ sender: UISlider) { num1Max = Int( sender.value ) num1RangeLabel.text = "Range: 0 - \(num1Max-1)" } // this function sets the text on num2RangeLabel to show the Range 0-? @IBAction func slider2(_ sender: UISlider) { num2Max = Int( sender.value ) num2RangeLabel.text = "Range: 0 - \(num2Max-1)" } // FINISH ME // link to the first slider // refers to the first slider @IBOutlet weak var slider1: UISlider! // FINISH ME // link to the second slider // refers to the second slider @IBOutlet weak var slider2: UISlider! func createRandomProblem(_ op:String) { // this gets a random number from 0 to num1Max-1 num1 = Int (arc4random_uniform(UInt32(num1Max))) // FINISH me // set the num1Label to num1 (but as a String) // HINT: create a String object String(?) num1Label.text = ????(num1) // this gets a random number from 0 to num2Max-1 num2 = Int (arc4random_uniform(UInt32(num2Max))) // FINISH me // set the num2Label to num2 (but as a String) // HINT: create a String object String(num2) num2Label.text = ???? // FINISH me // set the opLabel to op opLabel.???? = op // FINISH me // set the userAnswerTextField to "" userAnswerTextField.text ? ?? // FINISH me // set the correctIncorrectLabel to "" correctIncorrectLabel.???? = "" } // FINISH ME // link the + button to this function // this creates a random addition problem @IBAction func addButtonEvent(_ sender: UIButton) { createRandomProblem("+") } // FINISH ME // link the - button to this function // then write the code to create a new problem // (see the addButtonEvent) @IBAction func subtractButtonEvent(_ sender: UIButton) { // FINISH ME // call the method // createRandomProblem() and send to it the String "-" ??? } // FINISH ME // link the * button to this function // then write the code to create a new problem // (see the addButtonEvent) @IBAction func multiplyButtonEvent(_ sender: UIButton) { // FINISH ME // call the method // createRandomProblem() and send to it the String "*" ??? } // FINISH ME // link the / button to this function // then write the code to create a new problem // (see the addButtonEvent) @IBAction func divideButtonEvent(_ sender: UIButton) { // FINISH ME // call the method // createRandomProblem() and send to it the String "/" ??? } // FINISH ME // link the % button to this function // then write the code to create a new problem // (see the addButtonEvent) @IBAction func modButtonEvent(_ sender: UIButton) { // FINISH ME // call the method // createRandomProblem() and send to it the String "%" ???? } // FINISH ME // link the Check button to this function @IBAction func checkButtonEvent(_ sender: UIButton) { // get the text on the button let textOnButton = sender.title(for: .normal)! // FINISH ME // get the text on num1Label and unwrap it let num1 = Int(num1Label.????!) // FINISH ME // get the text on num2Label and unwrap it // Convert it to an Int let num2 = ???(num2Label.????!) // FINISH ME // get the text on userAnswerTextField and unwrap it // Convert it to an Int let userAnswer = ???(userAnswerTextField.????!) if let num1 = num1, let num2 = num2, let userAnswer = userAnswer { // FINISH ME // define (create) a variable called // correctAnswer and set it to 0 ???? // FINISH ME // define (create) a variable called // op and set it to opLabel.text! ???? // FINISH ME // finish checking for each op and // finding the correct answer // +, -, *, /, % if op == "+" { // FINISH ME // add num1 and num2 correctAnswer = ???? } else if op == "-" { // FINISH ME // subtract ????? } else if op == "*" { // FINISH ME // multiply ???? } else if op == "/" { // FINISH ME // divide if num2 == 0 { correctAnswer = 0 } else { correctAnswer = ???? } } else if op == "%" { // FINISH ME // mod if num2 == 0 { correctAnswer = 0 } else { correctAnswer = ???? } } if textOnButton == "Check" && correctAnswer == userAnswer { // FINISH ME // the user answer is correct, // so put "Correct!!!" in the // text field correctIncorrectLabel.???? = ????? } else { if textOnButton == "Show" { correctIncorrectLabel.text = "\(correctAnswer)" } else { // FINISH ME // the answer is incorrect, // so put incorrect on the text field correctIncorrectLabel.???? = ?????? } } } else { // FINISH ME // the answer is incorrect correctIncorrectLabel.???? = ???? } } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. // FINISH ME // initialize all of your UI objects text fields to "" num1Label.text ? "" opLabel.text ? ?? num2Label.text ? ?? userAnswerTextField.???? = ?? correctIncorrectLabel.text = "Click on +, -, *, /, or %" slider1.value = Float(num1Max) num1RangeLabel.text = "Range: 0 - \(num1Max-1)" slider2.value = Float(num2Max) num2RangeLabel.text = "Range: 0 - \(num1Max-1)" } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }