-
Notifications
You must be signed in to change notification settings - Fork 85
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
Amethyst - Hannah & Phalesa #72
base: main
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,200 @@ | |||
"use strict"; | |||
|
|||
const state = { |
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.
Love how you all chose to use this psuedostate! I think that it is great practice for what you will see in React though it will be utilized differently!
const temperatureElement = document.getElementById('temperature'); | ||
const increaseBtn = document.getElementById('increase-btn'); | ||
const decreaseBtn = document.getElementById('decrease-btn'); | ||
const landscapeImg = document.getElementById('landscape-img'); | ||
const emojiElement = document.getElementById('emoji'); | ||
const cityElement = document.getElementById('city'); | ||
const resetCityButton = document.getElementById('reset-city'); | ||
const skyElement = document.getElementById('sky'); | ||
const skyEmojiElement = document.getElementById('skyEmoji'); | ||
const checkCurrentTempElement = document.getElementById('check-current-temp'); |
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.
Pieces of code like this are usually found in an event handler that runs on the event DOMContentLoaded
, basically once the page is html is loaded on the webpage you will run a bunch of initial logic such as grabbing elements and adding event handlers to them. It will look something like this:
document.addEventListener("DOMContentLoaded", function () {
const increaseTemp = document.querySelector("#increase-temp");
const decreaseTemp = document.querySelector("#decrease-temp");
const displayTemp = document.querySelector("#display-temp");
const resetButton = document.querySelector("#reset-button");
const searchButton = document.querySelector("#search-button");
const cityName = document.getElementById("city-name");
const cityInput = document.getElementById("city-input");
const selectSky = document.querySelector("#sky-dropdown");
const result = document.querySelector("#sky");
const landscape = document.querySelector("#landscape");
increaseTemp.addEventListener("click", increaseTemperature);
decreaseTemp.addEventListener("click", decreaseTemperature);
...
}
This is also usually found at the bottom of the file too, that way you can put all your function definitions for event handlers above it!
function updateTemperatureDisplay(temperature) { | ||
temperatureElement.textContent = `${temperature}°F`; | ||
|
||
if (temperature >= 80) { |
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 can tell you all had fun with this one LOL
const findCityLocation = () => { | ||
let lat; | ||
let lon; | ||
return axios.get('http://127.0.0.1:5000/location', { | ||
params: { | ||
q: document.getElementById("city").value | ||
} | ||
}) | ||
.then( (response) => { | ||
console.log(response) | ||
console.log(document.getElementById("city").value); | ||
lat = response.data[0]['lat']; | ||
lon = response.data[0]['lon']; | ||
console.log('success in findLatitudeAndLongitude!', lat, lon); | ||
getWeather({ lat: lat, lon: lon}); | ||
}) | ||
.catch((error) => { | ||
console.log(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.
Here's an alternative to promise chaining! You can use the async/await
keywords to have your function wait until a promise is fulfilled and then you pass the results of that promise to other pieces of your function like assigning your return values as variables or other things like that. It looks something like this:
const findCityLocation = async () => {
let lat;
let lon;
const resp = await axios.get('http://127.0.0.1:5000/location', {
params: {
q: document.getElementById("city").value
}
})
try {
[lat, lon] = resp.data[0]
getWeather({ lat: lat, lon: lon});
} catch (error) {
console.log(error)
}
};
} | ||
|
||
//function to return city input | ||
function cityInput() { |
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.
Nice, I see you used the hoisting functionality of the function
keyword! Make sure to think about readability, however!
skyEmojiElement.textContent = '❄️❄️☃️☃️⛄️⛄️🤶🏾🥶🥶🥶⛄️⛄️⛄️❄️❄️❄️❄️🌨️🌨️🌨️🌨️☃️⛷️⛄️🤶🏾🥶❄️☃️🌨️☃️⛷️⛄️🤶🏾🥶❄️☃️❄️'; | ||
} | ||
|
||
} |
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.
Awesome job everyone! You really ate this one up! Please feel free to reach out to me if you have any questions about the comments I left or if you want to discuss anything in greater detail! ⭐️
No description provided.