Skip to content

Conversation

@github-classroom
Copy link

@github-classroom github-classroom bot commented Mar 9, 2024

👋! GitHub Classroom created this pull request as a place for your teacher to leave feedback on your work. It will update automatically. Don’t close or merge this pull request, unless you’re instructed to do so by your teacher.
In this pull request, your teacher can leave comments and feedback on your code. Click the Subscribe button to be notified if that happens.
Click the Files changed or Commits tab to see all of the changes pushed to main since the assignment started. Your teacher can see this too.

Notes for teachers

Use this PR to leave feedback. Here are some tips:

  • Click the Files changed tab to see all of the changes pushed to main since the assignment started. To leave comments on specific lines of code, put your cursor over a line of code and click the blue + (plus sign). To learn more about comments, read “Commenting on a pull request”.
  • Click the Commits tab to see the commits pushed to main. Click a commit to see specific changes.
  • If you turned on autograding, then click the Checks tab to see the results.
  • This page is an overview. It shows commits, line comments, and general comments. You can leave a general comment below.
    For more information about this pull request, read “Leaving assignment feedback in GitHub”.

Subscribed: @avauga03

Copy link
Member

@joemull joemull left a comment

Choose a reason for hiding this comment

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

Really excellent work! I have left some detailed comments here on GitHub, but a summary and mark will also be sent out later.

document.querySelectorAll(`[data-country="${path.dataset.country}"]`).forEach(svgPath => {
svgPath.classList.toggle('hover-effect', highlight);
});
}
Copy link
Member

Choose a reason for hiding this comment

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

This is great--I can see that you are solving a problem where the path being hovered over may just be one of several areas that make up that country.

function countryHighlights(genre, bookData) {
document.querySelectorAll('.genre-highlight').forEach(path => path.classList.remove('genre-highlight'));
Object.values(bookData).forEach(geographicalArea => {
(geographicalArea[genre] || []).forEach(book => {
Copy link
Member

Choose a reason for hiding this comment

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

I understand the desire to make things as compact as possible, and it's a common style that you see in JavaScript out in the world, including in guides and demos. But I would also encourage you to balance it with things that help with readability, like assigning things to descriptive variable names and avoiding executing methods on anonymous expressions.

Line 85 is an example of a method being executed on an anonymous expression, and it is a bit hard to read. I'd maybe add a variable name with something like this:

const booksInGenre = geographicalArea[genre] || []
booksInGenre.forEach( etc. )

This will help people who aren't as familiar with the data structure in booksData.json, and it will also help you later when you've forgotten the details and are coming back to your own code.

} else {
bookInfo.innerHTML += `<p>There are no books found for ${genre} in ${country}.</p>`;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This is quite a well designed function. The variables that you set at each level before going deeper in the data structure help a lot with readability.

Copy link
Member

Choose a reason for hiding this comment

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

Also, great use of filter.

countryHighlights(genreSelect.value, data);
})
.catch(error => console.error('There is an error when trying to fetch the book data:', error));
});
Copy link
Member

Choose a reason for hiding this comment

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

Great program design--this is the "controller" for your application's logic, and it delegates actions to the other functions in the program.

One thing I'd maybe change is to put the functions called by the controller above this function, in the order in which they are used. It's not a hard-and-fast rule but it does tend to be a convention that most functional programs follow. It is counterintuitive (or at least I found it so when I started programming) if you are used to laying out documents, because you might want the program to execute starting at the top and then going down. But it's a worthwhile switch to make for readability of your programs for other developers.

Copy link
Member

Choose a reason for hiding this comment

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

Also, well done implementing error handling, and also using arrow functions and forEach, which we did not officially cover in the module.

</circle>
<circle cx="1798.2" cy="719.3" id="2">
</circle>
</svg>
Copy link
Member

Choose a reason for hiding this comment

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

I understand why you pasted this into the HTML. If you'd like a challenge, you could try just using the external svg file. To do so I think you'd need to use JavaScript to load it into the DOM on page load, and then (and only then) execute the main "controller" function in your app. This might help the index.html file be easier to read and edit, with the SVG extracted away.

return Object.keys(bookData).find(continent =>
Object.values(bookData[continent]).flat().some(book => book.country === country)
);
}
Copy link
Member

Choose a reason for hiding this comment

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

Impressive use of these advanced methods!

Copy link
Member

Choose a reason for hiding this comment

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

Impressive JSON curation skills!

<!-- Search bar doesn't work, just a placeholder to visually show what the website would look like -->
<div class="search-bar">
<input type="text" placeholder="Search the website" id="searhbox">
</div>
Copy link
Member

Choose a reason for hiding this comment

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

I'd maybe have omitted this from this iteration, since the focus is really on the map and I'm not sure what I would be searching, so it's a bit of a distraction.

<option value="Horror">Horror</option>
<option value="Romance">Romance</option>
<option value="Thriller">Thriller</option>
</select>
Copy link
Member

Choose a reason for hiding this comment

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

Great!


-->
<svg id="svg-map" baseprofile="tiny" fill="#ececec" stroke="black" stroke-linecap="round" stroke-linejoin="round" stroke-width=".2" version="1.2" viewbox="0 0 2000 857" xmlns="http://www.w3.org/2000/svg">
<path d="M1383 261.6l1.5 1.8-2.9 0.8-2.4 1.1-5.9 0.8-5.3 1.3-2.4 2.8 1.9 2.7 1.4 3.2-2 2.7 0.8 2.5-0.9 2.3-5.2-0.2 3.1 4.2-3.1 1.7-1.4 3.8 1.1 3.9-1.8 1.8-2.1-0.6-4 0.9-0.2 1.7-4.1 0-2.3 3.7 0.8 5.4-6.6 2.7-3.9-0.6-0.9 1.4-3.4-0.8-5.3 1-9.6-3.3 3.9-5.8-1.1-4.1-4.3-1.1-1.2-4.1-2.7-5.1 1.6-3.5-2.5-1 0.5-4.7 0.6-8 5.9 2.5 3.9-0.9 0.4-2.9 4-0.9 2.6-2-0.2-5.1 4.2-1.3 0.3-2.2 2.9 1.7 1.6 0.2 3 0 4.3 1.4 1.8 0.7 3.4-2 2.1 1.2 0.9-2.9 3.2 0.1 0.6-0.9-0.2-2.6 1.7-2.2 3.3 1.4-0.1 2 1.7 0.3 0.9 5.4 2.7 2.1 1.5-1.4 2.2-0.6 2.5-2.9 3.8 0.5 5.4 0z" id="AF" name="Afghanistan" data-country="Afghanistan">
Copy link
Member

Choose a reason for hiding this comment

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

Really impressive the way you have tied the JSON data and the SVG paths together using a custom data-country attribute.

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.

2 participants