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 trialRico Petrini
431 PointsSpent hours on this please help me I really need help thanks for your time u help me thank you
HELP please
let numbers = [2,8,1,16,4,3,9]
var sum = 0
var counter = 0
// Enter your code below
while counter <= sum {
print(6[counter])
counter <= 1
}
1 Answer
Sarah Hurtgen
Treehouse Project ReviewerAre you on step 1?
It looks like you're currently looping through "while counter <= sum". This is heading towards the right direction, however the instructions want you to loop as long as "counter" is less than the number of items in the array, not the sum.
They also give a hint to use the count property, which counts up the number of items in your array. We use the count property by typing the name of the array and calling its count with dot notation.
let exampleArray = [3, 4, 26, 7, 99]
exampleArray.count
// this would give a count of 5
Once you have your while loop set, you then need to give it code within its body that will keep it from looping forever, since currently "counter" is set to zero, and nothing is changing that. I recommend re-watching the While and While Repeat video, this issue is discussed about 1 minute in.
Hope this helps!