NEW: Learn to build the incredible iOS 15 Weather app today! >>

SOLVED: Question: CheckPoint 4 (throwing errors) Why my code not working?

Forums > 100 Days of SwiftUI


My code is very similar to Paul's solution , but mine is not working

here is :

enum squareRootError: Error{
    case outOfBounds, noRoot

func CheckPoint4 (checkNumber: Int) throws -> Int {
    if checkNumber < 1 || checkNumber > 10_000 {
    throw squareRootError.outOfBounds
     for i in 1...100 {
        if (i * i) == checkNumber {
            return i }
    throw squareRootError.noRoot

let checkNumber = 6561

do {
    let rootNumber = try CheckPoint4 (checkNumber: 6561)
    print ("The square root of \(checkNumber) is \(rootNumber).")
}    catch {
    print ("sorry there was a problem")

Thank you in advance!



You need a closing brace } after the line throw squareRootError.noRoot to end your CheckPoint4 function.

Try to keep your indentation and matching braces lined up correctly; that will help you catch things like this.


If you select all the code and ctl+i will give you correct indents.


Thank you both @roosterboy and @@NigelGee

Don't know why I was so blind.

had been frustrated to see my code not working; now even more frustrated to realize I was blind .


Thank you guys and have a great Friday.



Hacking with Swift is sponsored by Sentry

SPONSORED With Sentry’s error and performance monitoring for iOS, you see mobile vitals that actually matter, can solve any latency issues quickly, and learn how each release is performing over time.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.