I need help on copy array with Spread operator task

Tell us what’s happening:
my solution is not giving me the supposed output, i dont know where my error is from

Your code so far


function copyMachine(arr, num) {
let newArr = [];
while (num >= 1) {
  // Only change code below this line
newArr += [[...arr]];
//newArr.push(arr)
  // Only change code above this line
  num--;
}

return newArr;
}

console.log(copyMachine([1, 2, 3], 5));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36.

Challenge: Copy an Array with the Spread Operator

Link to the challenge:

Hey @CodebanK!

It’s interesting because you wrote a comment that is actually the answer but then you didn’t apply it to your actual code. So I would see if I could use that comment to my advantage.

Hope that helps!

waoo, just removed the comment and it gave the right answer. though i had to comment the line before it. thanks you

1 Like