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 trialJennifer Riess
8,726 PointsHelp! Not sure if I have the concept down. Any hints would be welcome, but don't give the answer!
Thanks)
const numbers = [1,2,3,4,5,6,7,8,9,10];
let times10 = [];
numbers.forEach(number => {
times10 = number * 10;
numbers.push(times10);
});
// times10 should be: [10,20,30,40,50,60,70,80,90,100]
// Write your code below
3 Answers
Steven Parker
231,272 PointsThe 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
6,303 PointsHello 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!
hughvidler
1,321 PointsYou'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).