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 JavaScript Quickstart Arrays and Loops Create a forEach Loop

Can someone please tell me what I'm doing wrong here.

I don't know what I'm doing wrong, please help.

app.js
const numbers = [1,2,3,4,5,6,7,8,9,10];
let times5 = [];

// times5 should be: [5,10,15,20,25,30,35,40,45,50]
// Write your code below

numbers.forEach(times5 => alert(times5 *5));

2 Answers

const numbers = [1,2,3,4,5,6,7,8,9,10];
let times5 = [];

numbers.forEach((time) => {
    const newTime = time * 5;
  times5.push(newTime);
  return times5;
});

I think forEach may also return a new array, so you might be able to save the output directly into time5 - it didn't seem to work for me in the workspace though

Thank you! what you said worked.