Skip to content

Conversation

@R0EYK
Copy link

@R0EYK R0EYK commented Dec 12, 2024

No description provided.

Copy link
Member

@Tamir198 Tamir198 left a comment

Choose a reason for hiding this comment

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

You don't need to explain your code by adding comments, the code should explain it self with meaningful names

// Load countries from JSON file, once completed use displayCountries to render them
const loadCountries = async () => {
const grid = document.getElementById("countries-grid");

Copy link
Member

Choose a reason for hiding this comment

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

Please save your hardcoded strings into constants file

countries.forEach((country) => {
const countryElement = document.createElement("a");
countryElement.href = "#";
countryElement.className = "country scale-effect";
Copy link
Member

Choose a reason for hiding this comment

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

Don't use innerHtmL, its a dangerous method.

const filterCountries = async (region) => {
try {
const response = await fetch("./CountriesData.json");
const countries = await response.json();
Copy link
Member

Choose a reason for hiding this comment

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

This function should only do 1 thing and this is to filter the countries.
Extract the get data logic into separate function

// Load countries when the DOM is fully loaded
document.addEventListener("DOMContentLoaded", () => {
loadCountries();

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 a good practice to call dat fetching functions when the app first loads

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