What Am I doing worng here?

Tell us what’s happening:
My code runs perfectly


and fulfills all the requirements on VS Code and also on playcode io, but it fails the tests here. What is happening? what am I doing wrong?

  **Your code so far**
// The global variable
const bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];

// Change code below this line
function add(arr, bookName) {
newArr = [...arr];
newArr.push(bookName);
//const a = arr.concat(newArr)
return newArr;

// Change code above this line
}

// Change code below this line
function remove(arr, bookName) {
const newArr = [...arr]
const book_index = arr.indexOf(bookName);
if (book_index >= 0) {

  newArr.splice(book_index, 1);
  return newArr;

  // Change code above this line
  }
}
  **Your browser information:**

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0

Challenge: Refactor Global Variables Out of Functions

Link to the challenge:

you forgot to declare newArr.

OMG thank you so much. I’m so careless smh :sweat_smile:

1 Like