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

weather-report panthers Tiffany Rogers #90

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Tiffany-Rogers-Dev
Copy link

No description provided.

.catch((error) => {
alert(error);
})
};
Copy link

@mikellewade mikellewade Jan 11, 2023

Choose a reason for hiding this comment

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

Nice promise chaining for these functions, Tiffany! I have one refactoring advice for you and that is to implement the async &c await functionality of Javascript in order to make your code more concise and readable. doing something like:

const getAPI = async () => {
  let lat, long;
  
try {
   const response = await axios.get('http://127.0.0.1:5000/location', {
      params: {
        q: userSearch.value,
        format: 'json',
      }})
  
    lat = response.data[0].lat;
    long = response.data[0].lon;
    
   getWeather(lat, long) 
} catch (err) {
    console.log(err);
  }
}

Using the await keyword lets us stop the global execution for the function it is in and wait for the promise to be fulfilled. This allows us to cut out the promise chaining here and just save return information from the axios calls as variables. We can then use said variables like we ordinarily would in the then chain of the promise. Then we can use a try/catch block for error handling. Finally, I would suggest breaking the location and weather API calls into their own functions so that you can avoid nesting try/blocks and just overall concise code.

function increment(){
temp += 1;
temperature.textContent=temp
console.log(temp)

Choose a reason for hiding this comment

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

Remember to remove your console.logs before pushing into production!

<input type="text" id="city-search" value="Columbus" />
<button
style="

Choose a reason for hiding this comment

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

When doing this much styling it is best to move it inside of your css file so it doesn't congest your html files.

temperature.style.color="blue"
}else {
temperature.style.color="#1100ab"
}

Choose a reason for hiding this comment

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

So here you have the right idea for your if statements, however you could just put this here:

if (temp > 60) 

spring.style.display="none"
fall.style.display="none"
winter.style.display="flex"
}
Copy link

@mikellewade mikellewade Jan 11, 2023

Choose a reason for hiding this comment

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

So here, the refactor that I would suggest would start in the HTML file. Instead of putting all the landscapes I would just put one of them. Something like : <div id='landscape'></div> After that, I would change the code you have here into something like:

const landscape = document.getElementById('landscape')

if (temp >= 65) {
   landscape.innerHTML = 😎S☀️u🌞n🌅n🌞y😎
}

This way you can save your fingers from typing a lot more code! I would do the same thing in the dropDownValue function.

defaultSky.style.display = 'none';
};

dropdownValue()

Choose a reason for hiding this comment

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

I see you are invoking the certain functions in order to get the intital data displayed on the first render of the page. I would just move these all somewhere together. Given that you used the function keyword your functions have been hoisted and you can move them anywhere you please.

resetCityBtn.addEventListener('click', resetCity);
getWeatherBtn.addEventListener('click', getApi);
userSearch.addEventListener('input', displayInput);
skyDropDown.addEventListener('change', dropdownValue);

Choose a reason for hiding this comment

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

Here the only suggestion is to move these inside a registerHandlers function that is made the callback to theDOMContentLoadedevent handler.

}
footer{
text-align: center;
}

Choose a reason for hiding this comment

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

All in all, great work Tiffany! ✨

@Tiffany-Rogers-Dev
Copy link
Author

Tiffany-Rogers-Dev commented Jan 11, 2023 via email

@Tiffany-Rogers-Dev
Copy link
Author

Tiffany-Rogers-Dev commented Jan 11, 2023 via email

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