Iterate over Arrays with map need Help

Iterate over Arrays with map need Help
0

#1

What is wrong with this code? I’ve check similar topics and have tried shown solutions but still can’t pass the test. Shows error (“You should add three to each value in the array.”)

My code:

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

console.log(oldArray); 
console.log(newArray);


var newArray = oldArray;

#2

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

You’re reassigning newArray at the last line.


#3

Thank you! Now it passed


#4

Remove the last line.

You create a new array with each value added to three, but then you set the new array equal to the old array which will overwrite the new array.