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 trialKatherine Pangtay
1,933 PointsforEach
I'm not sure what i'm doing wrong.
const numbers = [1, 2, 3, 4, 5];
let total = 0;
// Write loop here:
numbers.forEach(function(number){
numbers.reduce(function(a,b){
return(+a)+(+b);
});
2 Answers
Steven Parker
231,236 PointsYou won't need "reduce" for this challenge. In fact, "reduce" is powerful enough to replace the entire loop, but this challenge wants you specifically to use "forEach".
The body of the loop only needs to accumulate the values in the "total".
Katherine Pangtay
1,933 Pointsya I was overthinking it! I figured it out thank you!