Tell us what’s happening:
I got the first three portions of this challenge to pass. The last one is quite confusing as it is a function within a function. Am I adding a new Book into the array and then subtracting one immediately at index of functional declaration of newstBookList
???
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 (array, bookName) {
return array.concat(bookName);
// Change code above this line
}
// Change code below this line
function remove (firstArray, bookName) {
var book_index = bookList.indexOf(bookName);
if (book_index >= 0) {
firstArray.splice(book_index, 1);
return firstArray;
// Change code above this line
}
}
var newBookList = add(bookList, 'A Brief History of Time');
var newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies');
//first we're adding a function within a function, which appears to be adding one book, and removing a book?
var newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies');
// console.log(bookList);
console.log(newerBookList)
// console.log(newestBookList);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36
.
Challenge: Refactor Global Variables Out of Functions
Link to the challenge: