Hello,
I tried to retake this exercice and I did that (doesn’t work):
// Change code below this line
function add (list, bookName) {
let newlist = list.slice();
return newlist.push(bookName);
instead of (works well):
// Change code below this line
function add (list, bookName) {
let newlist = list.slice();
newlist.push(bookName);
return newlist
When I make console.log(newlist.push(bookName)) this return “5”.
Could you please give me a explanation about this ?
Here under the full code
// 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) {
let newlist = list.slice();
//console.log(newlist.push(bookName))
return newlist.push(bookName);
// Change code above this line
}
// Change code below this line
function remove (bookName) {
var book_index = bookList.indexOf(bookName);
if (book_index >= 0) {
bookList.splice(book_index, 1);
return bookList;
// Change code above this line
}
}
var newBookList = add(bookList, 'A Brief History of Time');
console.log(newBookList)
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);