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 trialpolycount
1,582 PointsWhile loops code challenge question
I feel horrible for constantly having to ask these questions, but right when I feel I understand what it asks me to do, I end up being wrong! My code below is not working for some reason. I tried a couple other variants on the while loop that also did not work.
I don't want the answer given to me, but I would like a hint. That's one thing I think Treehouse could benefit from adding - little hints for those of us who can't seem to grasp the problems right off the bat.
Thanks, anyone!
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]
counter++
}
2 Answers
Matthew Young
5,133 PointsI'll try to give hints without giving the answer away.
Hint #1: Think about what numbers.count returns as a value.
Hint #2: Remember that the condition for a while loop must evaluate true for the loop to continue to execute.
Hope that nudges you in the right direction.
johann flores
Front End Web Development Techdegree Student 3,488 Pointswhile counter < 6 {
print(counter)
counter++
}