🎉 I just finished Day 8 of the #100DaysOfSwiftUI at https://www.hackingwithswift.com/100/swiftui/8
Got through Day 8 and made a Swift playground to find the square root using a function with error control. It works!
enum badInput: Error {
case badNumber
case noRoot
}
func findSquareRoot(of theNumber: Int) throws -> Int {
if theNumber < 1 || theNumber > 10_000 {
throw badInput.badNumber
}
for i in 1...100 {
if theNumber == i * i {
return i
}
}
throw badInput.noRoot
}
try? findSquareRoot(of: 36)
No comments:
Post a Comment