Array indexOf is not a function error message

Hi,

I’m working on the Functional Programming: Refactor Global Variables Out of Functions challenge, and it keep warning me that list.indexOf is not a function, which I can’t figure out why. Please help and let me know if there’s any unclarity regarding my question.

Your code so far


// the global variable
var bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];

/* This function should add a book to the list and return the list */
// New parameters should come before the bookName one

// Add your code below this line
function add (list, bookName) {
  
  return list.push(bookName);
  
  // Add your code above this line
}

/* This function should remove a book from the list and return the list */
// New parameters should come before the bookName one

// Add your code below this line
function remove (list, bookName) {
  let index = list.indexOf(bookName);
  if (index >= 0) {
    var first = list.slice(0,index);
    var second= list.slice(index);
    return first.concat(second);
    
    // Add your code above this line
    }
}

var newBookList = add(bookList, 'A Brief History of Time');
var newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies');
var newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies');

console.log(bookList);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/refactor-global-variables-out-of-functions

The issue is in the following add function:

function add (list, bookName) {
  
  return list.push(bookName);
  
  // Add your code above this line
}

Read about what the push method’s return value is. Your add function is returning whatever value the push method returns.

Hint: It is not an array.

Thanks! I got frustrated and stopped a couple days and when I come back, your answer really helps!.