Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import Foundation
struct HealthTracker {
private(set) var health = 100
mutating func takeDamage(_ amount: Int) {
health = max(health - amount, 0)
showHealth()
}
mutating func heal(_ amount: Int) {
health = min(health + amount, 100)
showHealth()
}
func showHealth() {
print("Health: \(health)")
}
}
var tracker = HealthTracker()
tracker.showHealth()
tracker.takeDamage(20)
tracker.heal(10)Coding works best on desktop or with an external keyboard.