Swift: Modify DoIncrease and doDecrease functions in the code below so that the counter is limited in 0 and 20 (including 0 and 20).

Computer Science

University of North Texas

Question Description

import UIKit

class ViewController: UIViewController {

var counter: Int?

@IBOutlet weak var plus: UIButton!

@IBOutlet weak var minus: UIButton!

@IBOutlet weak var cntLabel: UILabel!

@IBAction func DoIncrease(_ sender: Any) {

counter = counter! + 1

cntLabel.text = String(counter!)

}

@IBAction func DoDecrease(_ sender: Any) {

counter = counter! - 1

cntLabel.text = String(counter!)

}

override func viewDidLoad() {

super.viewDidLoad()

counter = 0

}

}

Student has agreed that all tutoring, explanations, and answers provided by the tutor will be used to help in the learning process and in accordance with Studypool's honor code & terms of service.

This question has not been answered.

Create a free account to get help with this and any other question!

Similar Questions
Related Tags