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

Trouble solving forEach task! Help!

Tried many things, but did not get to solve the problem. The last code I tried: numbers.forEach ( function (a) { times5.push (5*a); });

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 belo

numbers.forEach (times5.push (
function (a) {
return (5*a);
}
)
);

2 Answers

Kyle Knapp
Kyle Knapp
21,526 Points

You may need to adjust your syntax. Here are some examples to help:

const fruits = ["Apple", "Banana", "Cherry"];
fruits.forEach(fruit => console.log(fruit))
//prints Apple, Banana, Cherry

const newList = [];
const oldList = [1, 2, 3];
oldList.forEach(oldItem => newList.push(oldItem))
//newList now equals [1, 2, 3]

const printTimesThree = [1, 2, 3];
printTimesThree.forEach(number => console.log(number * 3))
//prints 3, 6, 9

Problem solved! Thank You! :-)