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 trialDavid Alberto Fuentes Ortiz
1,593 Pointsim stuck don't know
i don't know what im doing wrong or what to do
let numbers = [2,8,1,16,4,3,9]
var sum = 0
var counter = 0
// Enter your code below
while counter < numbers.count {
sum += numbers
counter++
}
1 Answer
Candace Sommer-Van Auken
2,032 PointsYou've almost got it! The only problem is in the line in the while loop that sums the numbers. It should read: sum += numbers[counter] Why? Because what you're doing is starting with the counter equal to zero. So you get the numbers array member at the zero position, and add it to sum. They you increase the counter to one and add the numbers array member at the one position to the sum, etc. Putting "sum += numbers" doesn't work because you can't add an array as though it were an integer.
I hope this helps!
David Alberto Fuentes Ortiz
1,593 PointsDavid Alberto Fuentes Ortiz
1,593 PointsTHANK YOU SO MUCH FOR ANSWERING.....