Iterate over Arrays with map excercise JS

having trouble solving this, anyone have a hint how to do this?:

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

// Only change code below this line.
var addThree = oldArray.map(function(val){
return val + 3;
});
console.log(addThree); // returns [4, 8, 12]
console.log(oldArray);
var newArray = oldArray;

anyone have any hints???

you actually have what you need … plus stuff you dont need is why its failing …

just change last line var newArray = oldArray to var newArray = addThree

it passes then … if you dont understand why post back

The solution is:

var oldArray = [1,2,3,4,5];
//only change code below this line
var newArray = oldArray.map(function(val) {
return val + 3;
});
console.log(addThree);
console.log(oldArray);

Hope that helps.

@annajuare: please do not post spoilers without making an effort to mask them. You can use spoiler tags like @PortableStick did in one of your other posts.

Please also make the effort to properly format your code, as you have been asked to do several times before.

If you need help doing either of these things, I will happily explain them in more detail.

1 Like