Skip to content

Conversation

@gboyega
Copy link
Owner

@gboyega gboyega commented Oct 18, 2019

Merging working branch with master

var content = document.getElementById("content");
var search = document.getElementById("search");

search.addEventListener("click", () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use an abstraction for the repeated code

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't think of that before. Will do that now. Thank you

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

js/index.js Outdated
var request = new XMLHttpRequest();
request.open('GET', url);
request.onload = () => {
if (request.status >= 200 && request.status < 400) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The success status code will always be 200. So if (request.status === 200) should be a sufficient check.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. Thanks

js/index.js Outdated
var books = data.items;
var eligible = [];
for (x = 0; x < books.length; x++) {
if (books[x].volumeInfo.imageLinks != null && books[x].volumeInfo.authors != null && books[x].volumeInfo.industryIdentifiers != null) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple if/else usually make the code difficult to read. Think of refactoring it or maybe see if you can use a switch

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a single if-else statement but has multiple conditions, and I think a switch statement will be longer. please advise appropriately

js/index.js Outdated

window.onload = () => {
url = "https://www.googleapis.com/books/v1/volumes?q=pride+prejudice&maxResults=40"
url = "https://www.googleapis.com/books/v1/volumes?q=pride+prejudice&download=epub&maxResults=40"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are repeating this URL. Declare it in the global scope and reuse it

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. had to use a function however

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants