-
Notifications
You must be signed in to change notification settings - Fork 100
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
base: main
Are you sure you want to change the base?
Panthers Jan L. #74
Conversation
} else if (state.temp >= 80) { | ||
tempColor.style.color = 'red'; | ||
newLS.src = `assets/hot1.jpeg`; | ||
} |
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.
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); | ||
}); | ||
}; |
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 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}`; |
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.
I love this use of the event object!
realTimeButton.addEventListener('click', realTimeClick); | ||
const reset = document.getElementById('resetButton'); | ||
reset.addEventListener('click', resetCity); | ||
}; |
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.
✨✨✨
No description provided.