-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shay Mashiah Country Assigment #21
base: main
Are you sure you want to change the base?
Shay Mashiah Country Assigment #21
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left you some comments
@@ -0,0 +1,88 @@ | |||
document.querySelector('.loader').style.display = 'none'; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change styles via css classes and not js
|
||
if (countryName) { | ||
fetch('./CountriesData.json') | ||
.then(response => response.json()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoded strings should be inside constants file
|
||
const selectedCountryName = document.createElement('h1'); | ||
selectedCountryName.innerHTML = selectedCountry.name; | ||
selectedCountryName.classList.add('h1'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using innerHTML
, it is a dangerous method
|
||
const countryPopulation = document.createElement('li'); | ||
countryPopulation.innerHTML = `<strong>Population:</strong> ${selectedCountry.population}`; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can extrac this into a function and call it inside a loop to prevent code duplication
countryDataList.appendChild(countryCapital); | ||
countryDataList.appendChild(countryDomain); | ||
countryDataList.appendChild(countryCurrencies); | ||
countryDataList.appendChild(countryLanguages); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be replaced with a loop :
const elements = [countryNativeName, countryPopulation, countryRegion, countrySubRegion];
elements.forEach(element => countryDataList.appendChild(element));
And so on
.then(response => response.json()) | ||
.then(data => { | ||
const container = document.querySelector('.countries-grid'); // המיכל שבו תוסיף את כל המדינות | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not use Hebrew comments, it will not support in every device, in addition the code should be self explanatory and understandable without comments
const countries = document.getElementsByClassName('country'); | ||
for (let i = 0; i < countries.length; i++) { | ||
const countryRegion = countries[i].getElementsByClassName('country-brief')[0].getElementsByTagName('li')[1].innerText.split(':')[1].trim(); | ||
if (region === 'All' || countryRegion === region) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line :
const countryRegion = countries[i].getElementsByClassName('country-brief')[0].getElementsByTagName('li')[1].innerText.split(':')[1].trim();
Is really long, you should split it into variables instead of really long line
No description provided.