Tell us what’s happening:
Passing 3 tests but failing the 4th. Any pointers will be appreciated.
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"];
// Change code below this line
function add (list, bookName) {
list = [...bookList]
list.push(bookName);
return list;
// Change code above this line
}
// Change code below this line
function remove (list, bookName) {
list = [...bookList]
var book_index = list.indexOf(bookName);
if (book_index >= 0) {
list.splice(book_index, 1);
return list;
// Change 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 (Linux; Android 10; SM-A908B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.110 Mobile Safari/537.36
.
Challenge: Refactor Global Variables Out of Functions
Link to the challenge: