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

Panthers Jan L. #74

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

Panthers Jan L. #74

wants to merge 7 commits into from

Conversation

janliii
Copy link

@janliii janliii commented Dec 12, 2022

No description provided.

} else if (state.temp >= 80) {
tempColor.style.color = 'red';
newLS.src = `assets/hot1.jpeg`;
}

Choose a reason for hiding this comment

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

The logic here is correct, the only thing that is that you didn't need to put state.temp >= 50 && state.temp < 59 and then (state.temp >= 60 && state.temp < 69). You could just do state.temp > 50 and state.temp > 60. These take care of the range between these two numbers.

.catch((error) => {
console.log('error!', 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.

You handled this nested promise chaining very well! However there is a way we can make this code more concise! Making use of the async & await functionality in Javascript:

const findLocation = async (query) => {
  try {
      const coordinates = await axios.get('http://127.0.0.1:5000/location', {
      params: {
        q: query,
        format: 'json',
      }})
  
      let latitude = coordinates.data[0].lat;
      let longitude = coordinates.data[0].lon;
     
      findWeather(latitude, longitude) 
    } catch (err) {
      console.log(err)
  }
} 

Essentially, the await keyword allows for us to stop the execution of the function we are in and wait for the promise it is attached to be fulfilled and resolved. Then we can save that returned data to a variable and go about our business! We will put this logic inside of try/catch blocks to handle errors. I also would suggest breaking the two functionalities (location and weather) into separate functions to avoid nesting.


selectSky.addEventListener('change', (event) => {
const result = document.querySelector('.result');
result.textContent = `The sky is ${event.target.value}`;

Choose a reason for hiding this comment

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

I love this use of the event object!

realTimeButton.addEventListener('click', realTimeClick);
const reset = document.getElementById('resetButton');
reset.addEventListener('click', resetCity);
};

Choose a reason for hiding this comment

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

✨✨✨

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