Slice and Splice Tests Failing

Tell us what’s happening:
The following code is not passing the test for this algorithm exercise, but the output i’m seeing matches the expected output. Can someone help me understand what I’m doing wrong?

Your code so far

function frankenSplice(arr1, arr2, n) {
  // It's alive. It's alive!
  let x = arr1.slice(0,arr1.length);
  let newArr = [...arr2];
  return newArr;

frankenSplice([1, 2], ["a", "b"], 1); 

Your browser information:

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

Link to the challenge:

1 Like

In the test case you show above, the return value should be ["a", 1, 2, "b"], but your function instead returns [ "a", [ 1, 2 ], "b" ].

You are inserting the entire copy of arr1 array into a copy of array arr2 at the index specified by n instead of just the arr1 elements.

1 Like

Ah thank you! Is there a way to print the brackets on arrays when you use console.log? My output here just looked like a,1,2,b not [a,[1,2],b].

which browser are you using?

If you use your browser’s console (Ctrl+Shft+J in Chrome) then you would see something like below.


I like using node to test my code. When running in node, you would see the following.


If you do not wan to install node, but want to use it, I suggest using

See below your code using


This is great! Thank you! I was just using the freecodecamp exercise output area to test my code.

Sometimes that “fake console output area” does not always convey what is really going on. It is always best to use the browser’s console to see what is really going on.