Slice and Splice Not Working

Slice and Splice Not Working
0

#1

Tell us what’s happening:

Why not passing the tests? LET ME PASS

Your code so far


function frankenSplice(arr1, arr2, n) {
newArr= arr2.slice();
  for(i=0;i<arr1.length;i++){
    //need to add n+i as first arg because otherwise it keeps adding the elements @ the same position each run of the loop & we dont want them placed in reverse order in the newArr
newArr.splice(n+i,0,arr1[i]);
    }
  console.log(newArr);
}
frankenSplice([1, 2, 3], [4, 5, 6], 1);

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/slice-and-splice


#2

You are getting a warning that you need to declare newArr. Look through your entire code and make sure you are declaring each variable locally inside the function. You have 2 variables which need to be declared.

Also, your function needs to return a value. Currently, you are just displaying newArr to the console which is not the same as returning a value. Since you are not explicitly returning a value, JavaScript returns the value undefined for you.