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
Rosana Hernandez
1,346 PointsWhile Loops 2 of 2 Challenge
Have exhausted all possibilities with this challenge; including those suggested in the community and not getting through the challenge...All works fine in my playground! Here is my answer:
while counter < numbers.count {
sum += numbers[counter]
counter++
}
Help!
Challenge: Using the value of counter as an index value, retrieve each value from the array and add it to the value of sum.
let numbers = [2,8,1,16,4,3,9] var sum = 0 var counter = 0
Part 1: while counter < numbers.count { print (numbers[counter]);counter++ }
6 Answers
Jhoan Arango
14,575 PointsHello Rosana:
I am not sure 100% what is going on with your code, or what you are missing. But it looks Ok to me, I went to the challenge and did it myself to compare it to yours.
Here is my code
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++
}
This passes just fine. Perhaps you deleted something by accident ? give it another try see if it works.
Rosana Hernandez
1,346 PointsNathan, Elaborated on detail. Thanks for your help.
Rosana Hernandez
1,346 PointsJhoan, My thoughts exactly. Still not working...
Jhoan Arango
14,575 PointsWould you please tell me what is it telling you ?
Rosana Hernandez
1,346 Points"Make sure your condition allows for iteration over all elements in the numbers array and check your calculation of sum!"
Jhoan Arango
14,575 PointsI have no clue what is going on.. It could be the compiler. Have you tried closing your browser and trying it again ?
Rosana Hernandez
1,346 PointsMultiple times Jhoan! :D It's quite the head scratcher, isn't it...
Jhoan Arango
14,575 PointsTry copying and pasting my code into the challenge.. delete the one they give you.
Rosana Hernandez
1,346 PointsDeleting the previous code worked. Thanks for the tip! :D Woot, woot.
Jhoan Arango
14,575 Pointslol welcome, glad you can move on now..
Richard Garrison
827 PointsI had to do the same! Absolutely ridiculous waste of time!!!
Nathan Tallack
22,164 PointsNathan Tallack
22,164 PointsCan you link to the challenge for me?