Implement the Slice and Splice Algorithm - Test cases failing despite correct function behavior

Tell us what’s happening:

I have tried all of the test cases with console.log() and they seem to return the correct thing, though none of the test cases are passing. I think there is something simple I don’t understand about the freeCodeCamp IDE. Someone tell me why none of my test cases are passing please.

Your code so far

function frankenSplice(arr1, arr2, index) {
  newArr = new Array(arr1.length + arr2.length);
  for (let i = 0; i < newArr.length; i++) {
    if (i < index) {
      newArr[i] = arr2[i];
    }
    else if (i > index + arr1.length - 1) {
      newArr[i] = arr2[i - arr1.length];
    }
    else {
      newArr[i] = arr1[i-index];
    }
  }
  return newArr;
}

Your browser information:

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

Challenge Information:

Implement the Slice and Splice Algorithm - Implement the Slice and Splice Algorithm
https://www.freecodecamp.org/learn/full-stack-developer/lab-slice-and-splice/implement-the-slice-and-splice-algorithm

Did you declare this variable?

Wow, haha, I knew it was something like that! My code still seemed to compile and work correctly on my local environment though? I don’t know why it was working there without being declared properly.

fCC runs your code in ‘strict’ mode, as letting variables be used undeclared can lead to some very confusing errors. It is recommended to use ‘strict’ mode for all professional JS code.

hyy instead of using the ifs use slice because you wont modify the original array plus use spread operator(…) while calling the arrays in the built in function and use push() function to insert the first array and the last part of second array. hope this helps