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 Array Iteration Methods Array Iteration Practice forEach()

Jennifer Riess
Jennifer Riess
8,726 Points

Help! Not sure if I have the concept down. Any hints would be welcome, but don't give the answer!


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

numbers.forEach(number => {
    times10 = number * 10;

// times10 should be: [10,20,30,40,50,60,70,80,90,100]
// Write your code below

3 Answers

Steven Parker
Steven Parker
216,768 Points

The instructions say you should be "storing these new numbers in the times10 array.", but this code is pushing them onto the "numbers" array.

Also, to be able to access the "times10" array, you'll need to give your temporary variable a different name. Otherwise, the assignment replaces the new array with a single value.

Alec Meyer
Alec Meyer
6,303 Points

Hello Jennifer,

Hopefully I can give you some insight into what is going on without giving the answer directly.

numbers is an array which is like a list of numbers. You are going through each number in the numbers array and adding it to the end of the end of the original array.

In the comment it says to make changes to times10 which is also declared as an array, but not used as such inside of your loop. Hopefully that helps!

You're so close!

You've named your variable that holds the new number the same as your array, which is effectively overwriting your original array with a single int for each of the numbers. So by the end your times10 = 100 and not an array of all of your new numbers.

You can use const for your array since we're just pushing the numbers into the array without reassigning it (const restricts reassignment, which in this case is useful).