Good Morning all !
Seems I am still unsure why things went wonky here.
Here is the code :
// 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
let myBooks=bookList.slice();
function add (myBooks,bookName) {
return myBooks.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 (myBooks,bookName) {
if (myBooks.indexOf(bookName) >= 0) {
let myIndex=myBooks.indexOf(bookName);
return myBooks.splice(myIndex,1);
// Add your code above this line
}
}
var newBookList = add(myBooks, 'A Brief History of Time');
var newerBookList = remove(myBooks, 'On The Electrodynamics of Moving Bodies');
var newestBookList = remove(add(myBooks, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies');
console.log(bookList);
Now it is complaining about the myBooks.indexOf not being a function. also the console.log (bookList) is not spewing forth the original list. In testing I have moved a console.log(myBooks) around a bit and that all seems fine. until you get to the bottom.
Finally , in checking some of the other solutions available, I noted that for some reason everyone seems to be putting the copy of the array into the function instead of in the global and using that as I have. Why is that ?
Thank you in advance. I am sure its just early morning non-caffinated brain, but thank you for your time. in advance. it is greatly appreciated !