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

JavaScript Practice forEach in JavaScript Practice forEach forEach Practice - 1

Katherine Pangtay
Katherine Pangtay
1,933 Points

forEach

I'm not sure what i'm doing wrong.

app.js
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
Steven Parker
231,248 Points

You 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
Katherine Pangtay
1,933 Points

ya I was overthinking it! I figured it out thank you!