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

johnny louifils
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
johnny louifils
Full Stack JavaScript Techdegree Graduate 18,926 Points

How do you put the push method in this code

Every time I try to put the push method in the times3 array it telling to restart my work

app.js
const numbers = [1,2,3,4,5,6,7,8,9,10];
let times5 = [];
numbers.forEach(function(times5) {
})
// times5 should be: [5,10,15,20,25,30,35,40,45,50]
// Write your code below

Hey Johnny - In the closure you're going to get a number from the numbers array. Then inside that closure, you'll multiply times 5 and push the result onto the times5 array.

Cheers

_Ben

1 Answer

Hey - no worries. Try this:

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

let times5 = [];

numbers.forEach(function(number) {
    // Multiply the number times 5.
    number = number * 5;

    // Push the number onto the array.
    times5.push(number);
});