Skip to content

Commit 45a809b

Browse files
check for null case booklist
1 parent f935630 commit 45a809b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

ebooks/book.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
const url = window.location && window.location.toString().split('/');
44
const bookId = url[url.length - 1].match(/(\d+)/)[0];
55

6-
if (JSON.parse(localStorage.getItem('booklist'))[bookId]) {
6+
const currentList = JSON.parse(localStorage.getItem('booklist'));
7+
if (currentList && currentList[bookId]) {
78
// book already in list
89
addbtn.html('Remove book from My Book List')
910
addbtn.css("background-color", "indianred");
@@ -31,7 +32,7 @@
3132
bookId: bookId,
3233
imgSrc: $('img.cover-art').attr('src'),
3334
author: author,
34-
url: window.location
35+
url: window.location.href
3536
};
3637

3738
const newList = { ...JSON.parse(localStorage.getItem('booklist')) };

0 commit comments

Comments
 (0)