Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ShayMashiah
Copy link

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.

Left you some comments

@@ -0,0 +1,88 @@
document.querySelector('.loader').style.display = 'none';

Copy link
Member

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())
Copy link
Member

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');
Copy link
Member

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}`;

Copy link
Member

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);
Copy link
Member

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'); // המיכל שבו תוסיף את כל המדינות

Copy link
Member

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) {
Copy link
Member

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

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