Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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); });

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! :-)