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

johnny louifils
.a{fill-rule:evenodd;}techdegree seal-36
johnny louifils
Full Stack JavaScript Techdegree Graduate 18,919 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

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.



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.