Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Solution: Tower Defense Game

Can I please get help with this proactice project

I was putting in my solution into the playground, this is what I typed:

let distanceBetweenX = towerX - enemyX
let squaredXDistance = distanceBetweenX * distanceBetweenX

let distanceBetweenY = towerY - enemyY
let squaredYDistance = distanceBetweenY * distanceBetweenY

let sumOfSquares = squaredXDistance + squaredYDistance

The results for 4 of the constants did not print in the REPL. Only for the first constant. I also received an error in the debug area:

libc++abi.dylib: terminating with uncaught exception of type NSException

I am using Swift 4. Can someone please explain why this did not work in my IDE?

Also, I feel like the jump from learning the operators to jumping right into such complex arimathic solutions was rather jarring and overwhelming. Thank you.

1 Answer

Meg Dooley
Meg Dooley
7,321 Points

Hi Ellis

I copied your code into my more recent version of Xcode (10.0) and it worked fine so it might be a bug? Also - I often get overwhelmed by the math based challenges too so I usually spend some time googling the arithmetic needed before I attempt them. I felt a bit disheartened at first that I had to do that but there's really no need to be, most of us haven't even thought about math since we left school after all! I also find it handy to write down useful math formulas as they come up and post them to my desktop or sometimes on post-it notes on the wall behind my laptop so i can easily remind myself of what to do if I need it for a future code challenge. Hope that helps!