Functional Programming - Refactor Global Variables Out of Functions

Tell us what’s happening:
Describe your issue in detail here.
Could someone please explain to me why this is 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(bookName) {
  let newBookList = bookList.slice()
  newBookList.push(bookName);
  return newBookList;
  
  // Change code above this line
}

// Change code below this line
function remove(bookName) {
  let newBookList = bookList.slice()
  const book_index = newBookList.indexOf(bookName);
  if (book_index >= 0) {

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

    // Change code above this line
    }
}

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Safari/605.1.15

Challenge: Functional Programming - Refactor Global Variables Out of Functions

Link to the challenge:

Both functions still rely on the global variable. Instead they should use array of books, that’s passed to the function.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.