Iterate over Arrays with map (Challenge 239 Help)

Hey guys, no idea what I’m doing wrong here. Thanks for the help

This is what I have so far

var oldArray = [1,2,3,4,5];

// Only change code below this line.
var newArray = oldArray.map(function(val) {
      return val + 3;
});
var newArray = oldArray;

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36.

Link to the challenge:
https://www.freecodecamp.org/challenges/iterate-over-arrays-with-map

The map() function returns a new array (which you store in newArray) and does not change oldArray. So on the last line you are overwriting the correct result.

1 Like

Hello so your code is right accept one thing. You redeclare newArray! So first you declare it to equal the .map() and then after that you redeclare it to equal the oldArray. Just remove the last line and it’ll work!

2 Likes