From 45a809bcc1124f77bc4345a5155fcbc3b9a140e2 Mon Sep 17 00:00:00 2001 From: Adam Undus Date: Thu, 8 Oct 2020 14:59:05 -0400 Subject: [PATCH] check for null case booklist --- ebooks/book.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ebooks/book.js b/ebooks/book.js index 57cf919..bc02229 100644 --- a/ebooks/book.js +++ b/ebooks/book.js @@ -3,7 +3,8 @@ const url = window.location && window.location.toString().split('/'); const bookId = url[url.length - 1].match(/(\d+)/)[0]; - if (JSON.parse(localStorage.getItem('booklist'))[bookId]) { + const currentList = JSON.parse(localStorage.getItem('booklist')); + if (currentList && currentList[bookId]) { // book already in list addbtn.html('Remove book from My Book List') addbtn.css("background-color", "indianred"); @@ -31,7 +32,7 @@ bookId: bookId, imgSrc: $('img.cover-art').attr('src'), author: author, - url: window.location + url: window.location.href }; const newList = { ...JSON.parse(localStorage.getItem('booklist')) };