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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![ben sasser](https://secure.gravatar.com/avatar/76764e745987dac7cfa65f6161047307?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
ben sasser
476 Pointsdon't know how to retrieve the value from the array and add it to the sum.. my newValue statement is definitely wrong ha
Thank you
let numbers = [2,8,1,16,4,3,9]
var sum = 0
var counter = 0
while counter < numbers.count {
(numbers[counter])
counter++ }
var newValue = counter + numbers
sum = sum + newValue
// Enter your code below
![ben sasser](https://secure.gravatar.com/avatar/76764e745987dac7cfa65f6161047307?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
ben sasser
476 Pointsto retrieve the values from the numbers array and go up by 1 index each time???
![Kyler Smith](https://uploads.teamtreehouse.com/production/profile-photos/3376132/micro_1048463_1377547785796780_1645531499_o.jpg)
Kyler Smith
10,110 PointsClose! In order to retrieve it, you would be needing to store it in a variable though (maybe the variable 'sum'? :) ). Try adding that to sum.
sum += numbers[counter]
![ben sasser](https://secure.gravatar.com/avatar/76764e745987dac7cfa65f6161047307?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
ben sasser
476 Pointsstill doing something wrong.. Sorry for being so bad haha. Here is the new code :
let numbers = [2,8,1,16,4,3,9] var sum =0 var counter = 0
while counter < numbers.count { (numbers[counter]) counter++ }
sum += numbers[counter]
var newValue = counter + numbers
sum = sum + newValue
![Kyler Smith](https://uploads.teamtreehouse.com/production/profile-photos/3376132/micro_1048463_1377547785796780_1645531499_o.jpg)
Kyler Smith
10,110 PointsWe all started somewhere! Those last 2 lines can go because they are not needed in the calculation.
let numbers = [2,8,1,16,4,3,9]
var sum = 0
var counter = 0
while counter < numbers.count {
/* (numbers[counter]) this is what you originally had.
All you needed to do was add that to sum each time you went through the loop*/
sum += numbers[counter]
counter++
}
/* sum += numbers[counter]
this line goes inside of the body of your while loop.
It needs to be after the first bracket '{' but before the 'counter++'.
Because you are using counter as an index,
you don't want to increment it before you can grab the value from the array. */
// var newValue = counter + numbers
// sum = sum + newValue
1 Answer
![Jennifer Nordell](https://uploads.teamtreehouse.com/production/profile-photos/5432702/micro_jen-square.jpg)
Jennifer Nordell
Treehouse TeacherAs I posted earlier, this is the entirety of the code needed:
let numbers = [2,8,1,16,4,3,9]
var sum = 0
var counter = 0
while counter < numbers.count {
sum += numbers[counter]
counter++
}
![ben sasser](https://secure.gravatar.com/avatar/76764e745987dac7cfa65f6161047307?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
ben sasser
476 Pointssigh haha. maybe I'm just tired... thank you guys for the help.
Kyler Smith
10,110 PointsKyler Smith
10,110 PointsIn the body of your while loop you have the line that reads
(numbers[counter])
what purpose do you believe it serves?