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 trialMarley Barrett
1,818 PointsI do not understand step 2 help me
I have step one down but I cannot get step 2
let numbers = [2,8,1,16,4,3,9]
var sum = 0
var counter = 0
// Enter your code below
while counter < numbers.count {
print(numbers[counter])
counter += 1
}
while counter < numbers.count {
(numbers[counter]) counter == 1
}
1 Answer
Sean Wilson
2,572 PointsHi Marley,
Step 2 of the challenge is about adding up all the values inside of 'numbers'. You have to store the added up values inside of 'sum'.
Your answer needs to assign a new value into 'sum' on every iteration.
There's another gotcha type issue in your code. You have two while loops and they both check the 'counter' value as the condition for continuing to loop. However, after the first loop finishes, 'counter' will equal 'numbers.count' - since that's when the first loop will terminate. The second loop will never execute because the condition is false from the start. Do your solution, you will only need 1 while loop.
I hope that helps.