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 Swift 2.0 Collections and Control Flow Control Flow With Loops While and Repeat While

Stuck on Part 1 of 2.

Hi -

Seems this challenge isn’t accepting what i think is correct...

let numbers = [2,8,1,16,4,3,9] var sum = 0 var counter = 0

while counter < numbers.count { sum += numbers[counter] counter += 1 }

….It works in xCode

Or maybe it’s just me…any thoughts?

Lionel

2 Answers

andren
andren
28,558 Points

Your code is fine, in fact nowadays it's more correct than the solution the challenge is looking for.

The challenge checker can often be quite picky, even if the result is correct it might mark it as wrong if your solution lacks some specific thing it is looking for, in this case the problem is that it expects you to increase the counter by using the increment operator like this "counter++", incrementing it any other way will be marked as wrong.

It is worth nothing that the increment operator along with the decrement operator are no longer supported in swift 3, so you should actually avoid using them when programming in swift these days, these challenges and videos were made with swift 2 in mind though, which is why they are expecting you to use them.

Thanks that worked!