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 trialShane Gilpatrick
Android Development Techdegree Student 692 PointsCant figure out how to do 2nd part of task.
I know the 1st task is
while counter < numbers.count {
print(numbers[counter])
counter++
}
but I can not figure out the 2nd part which is this... Using the value of counter as an index value, retrieve each value from the array and add it to the value of sum.
For example: sum = sum + newValue. Or you could use the compound addition operator sum += newValue where newValue is the value retrieved from the array.
Shane Gilpatrick
Android Development Techdegree Student 692 PointsI tried that and it did not work... Im going to keep messing with it
1 Answer
Greg Kaleka
39,021 PointsHi Shane,
You're already correctly using counter as an index. Now, instead of printing that value, add it to the variable sum
:
while counter < numbers.count {
sum += numbers[counter]
counter++
}
Make sense?
Cheers
Greg
Shane Gilpatrick
Android Development Techdegree Student 692 PointsYes it makes perfect sense. I knew it would be something that i was just over looking.
Thank You!
Shane.
theodore eisensøe
1,107 Pointstheodore eisensøe
1,107 Pointsi am pretty sure this is what you are looking for,
while counter < 1 { print(counter) counter++ }