We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
class Person {
var age: Int = 0
init (initialAge: Int) {
if initialAge > 0 {
age = initialAge
} else {
age = 0
print("Age is not valid, setting age to 0.")
}
}
func amIOld () {
if age < 13 {
print("You are young.")
} else if age >= 13 && age < 18 {
print("You are a teenager.")
} else {
print("You are old.")
}
}
func yearPasses() {
age += 1
}
}
Day 4: Class vs. Instance
You are viewing a single comment's thread. Return to all comments →
I think Swift is fine, this passes everything: