-
Notifications
You must be signed in to change notification settings - Fork 100
Tigers - Mica and Misha #83
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
base: main
Are you sure you want to change the base?
Changes from all commits
c3d459f
d5a089d
553b4a8
f12f219
9ecc9e4
ca90b0f
0b15b72
5495f9c
b92cf28
63a6e77
12b4b1c
1220c69
ea91fb4
c466806
9ae867d
4f27a8d
4e1bf48
39d85ce
a56b054
8d49772
8fbe1e8
6901c88
d29fab1
f5d24b1
465ddab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| const state = { | ||
| Temperature: 0, | ||
| city: 'Seattle', | ||
| sky: 'sunny', | ||
| latitude: 0, | ||
| longitude: 0, | ||
| }; | ||
|
|
||
| const increaseTemp = (event) => { | ||
| const tempContainer = document.querySelector('#Temperature'); | ||
| console.log('increaseTemp clicked'); | ||
| state.Temperature = Math.round(state.Temperature + 1); | ||
| tempContainer.textContent = `${state.Temperature}`; | ||
| tempRange(); | ||
| }; | ||
| // hello this is a new branch!! | ||
|
|
||
| const decreaseTemp = (event) => { | ||
| const tempContainer = document.querySelector('#Temperature'); | ||
| state.Temperature = Math.round(state.Temperature - 1); | ||
| tempContainer.textContent = `${state.Temperature}`; | ||
| tempRange(); | ||
| }; | ||
|
|
||
| const tempRange = () => { | ||
| const tempContainer = document.querySelector('#Temperature'); | ||
| const landscapeContainer = document.querySelector('#landscape'); | ||
| if (state.Temperature >= 80) { | ||
| tempContainer.style.color = 'red'; | ||
| landscapeContainer.textContent = '🌵__🐍_🦂_🌵🌵__🐍_🏜_🦂'; | ||
| } else if (state.Temperature <= 79 && state.Temperature >= 70) { | ||
| tempContainer.style.color = 'orange'; | ||
| landscapeContainer.textContent = '🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷'; | ||
| } else if (state.Temperature <= 69 && state.Temperature >= 60) { | ||
| tempContainer.style.color = 'yellow'; | ||
| landscapeContainer.textContent = '🌾🌾_🍃_🪨__🛤_🌾🌾🌾_🍃'; | ||
| } else if (state.Temperature <= 59 && state.Temperature >= 50) { | ||
| tempContainer.style.color = 'green'; | ||
| landscapeContainer.textContent = '🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲'; | ||
| } else if (state.Temperature <= 49) { | ||
| tempContainer.style.color = 'teal'; | ||
| landscapeContainer.textContent = '🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲'; | ||
| } | ||
| }; | ||
|
Comment on lines
+28
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How might you refactor this so the logic is more data driven? Here you have several if/else if statements. What if you had an object with the keys as the temperature and the values as the It could look something like this: const tempColors = [
[49, 'blue'],
[59, 'green'],
[69, 'gold'],
[79, 'orange'],
[null, 'red'],
];
const getColorForTemp = (temp) => {
for (const [boundaryTemp, color] of tempColors) {
if (boundaryTemp === null || temp <= boundaryTemp) {
return color;
}
}
}; |
||
|
|
||
| const updateSky = (event) => { | ||
| const skyContainer = document.querySelector('#skySelect'); | ||
| const skyBannerContainer = document.querySelector('#skyBanner'); | ||
| state.sky = skyContainer.value; | ||
| if (state.sky === 'sunny') { | ||
| skyBannerContainer.textContent = '☁️ ☁️ ☁️ ☀️ ☁️ ☁️'; | ||
| } else if (state.sky === 'cloudy') { | ||
| skyBannerContainer.textContent = '☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️'; | ||
| } else if (state.sky === 'rainy') { | ||
| skyBannerContainer.textContent = '🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧'; | ||
| } else if (state.sky === 'snowy') { | ||
| skyBannerContainer.textContent = '🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨'; | ||
| } | ||
| }; | ||
|
|
||
| const chooseCityName = (event) => { | ||
| const cityName = document.querySelector('#cityName'); | ||
| const inputContainer = document.querySelector('#inputCityName'); | ||
| state.city = inputContainer.value; | ||
| cityName.textContent = state.city; | ||
| }; | ||
|
|
||
| const resetCityName = (event) => { | ||
| const cityName = document.querySelector('#cityName'); | ||
|
Comment on lines
+62
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we are repeating code on lines 62 and 69! Maybe we can create global variables that will hold elements like this that will be used more than once |
||
| const inputContainer = document.querySelector('#inputCityName'); | ||
| state.city = 'Seattle'; | ||
| inputContainer.value = ''; | ||
| cityName.textContent = state.city; | ||
| }; | ||
|
|
||
| const updateTemperature = (event) => { | ||
| const tempContainer = document.querySelector('#Temperature'); | ||
| axios | ||
| .get(`http://localhost:5000/location?q=${state.city}`) | ||
| .then((response) => { | ||
| state.latitude = response.data[0].lat; | ||
| state.longitude = response.data[0].lon; | ||
| console.log(response.data); | ||
| axios | ||
| .get( | ||
| `http://localhost:5000/weather?lat=${state.latitude}&lon=${state.longitude}` | ||
| ) | ||
| .then((response) => { | ||
| const temperatureKelvin = response.data.main.temp; | ||
| state.Temperature = ((temperatureKelvin - 273.15) * 9) / 5 + 32; | ||
| tempContainer.textContent = `${Math.round(state.Temperature)}`; | ||
| tempRange(); | ||
| console.log(response.data); | ||
| }) | ||
| .catch((error) => { | ||
| console.log('OpenWeather GET request error'); | ||
| }); | ||
| }) | ||
| .catch((error) => { | ||
| console.log('LocationIQ GET request error'); | ||
| }); | ||
| }; | ||
|
Comment on lines
+78
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good indentation! makes the promises easier to read 👍 |
||
|
|
||
| const registerEventHandlers = (event) => { | ||
| const increaseTempButton = document.querySelector('#increaseTempButton'); | ||
| increaseTempButton.addEventListener('click', increaseTemp); | ||
| // increaseTempButton.addEventListener('click', tempRange); | ||
| const decreaseTempButton = document.querySelector('#decreaseTempButton'); | ||
| decreaseTempButton.addEventListener('click', decreaseTemp); | ||
| // decreaseTempButton.addEventListener('click', tempRange); | ||
| const inputCityName = document.querySelector('#inputCityName'); | ||
| inputCityName.addEventListener('input', chooseCityName); | ||
| const resetCityNameButton = document.querySelector('#resetCityName'); | ||
| resetCityNameButton.addEventListener('click', resetCityName); | ||
| const updateTempButton = document.querySelector('#updateTempButton'); | ||
| updateTempButton.addEventListener('click', updateTemperature); | ||
| const skySelect = document.querySelector('#skySelect'); | ||
| skySelect.addEventListener('change', updateSky); | ||
| }; | ||
|
|
||
| document.addEventListener('DOMContentLoaded', registerEventHandlers); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| body { | ||
| display: grid; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooo nice job using css grid! 👍 |
||
| grid-template-columns: 1fr 2fr; | ||
| grid-template-rows: auto auto auto auto auto; | ||
| grid-gap: 1rem; | ||
| background-color: rgb(147, 227, 247); | ||
| margin: 1rem; | ||
| } | ||
|
|
||
| /* Flexbox Page Layout */ | ||
| .titleBlock { | ||
| grid-row: 1; | ||
| grid-column: span 3; | ||
| display: grid; | ||
| align-self: center; | ||
| } | ||
|
|
||
| .cityNameBlock, | ||
| .skyConditionBlock, | ||
| .temperatureBlock { | ||
| border-radius: 8px; | ||
| padding: 2rem; | ||
| background-color: white; | ||
| } | ||
|
|
||
| .cityNameBlock { | ||
| grid-row: 3; | ||
| text-align: center; | ||
| } | ||
|
|
||
| .skyConditionBlock { | ||
| grid-row: 4; | ||
| text-align: center; | ||
| } | ||
|
|
||
| .temperatureBlock { | ||
| grid-row: 3 / span 3; | ||
| grid-column: 2; | ||
| text-align: center; | ||
| align-self: center; | ||
| } | ||
|
|
||
| /* Specific Elements */ | ||
| .banner { | ||
| grid-column: span 3; | ||
| text-align: center; | ||
| } | ||
|
|
||
| #skyBanner { | ||
| grid-row: 2; | ||
| } | ||
|
|
||
| #siteTitle { | ||
| font-size: larger; | ||
| text-align: left; | ||
| } | ||
|
|
||
| #cityName { | ||
| text-align: left; | ||
| } | ||
|
|
||
| #resetCityName { | ||
| border-radius: 3em; | ||
| } | ||
|
|
||
| #skySelect { | ||
| background-color:rgb(230, 191, 243); | ||
| border-radius: 3em; | ||
| } | ||
|
|
||
| #cityName { | ||
| font-size: larger; | ||
| } | ||
|
|
||
| #increaseTempButton { | ||
| background-color: bisque; | ||
| border-radius: 3em; | ||
|
|
||
| } | ||
|
|
||
| #Temperature { | ||
| font-size: 30px; | ||
| } | ||
|
|
||
| #decreaseTempButton { | ||
| background-color: bisque; | ||
| border-radius: 3em; | ||
| } | ||
|
|
||
| #updateTempButton { | ||
| background-color: bisque; | ||
| border-radius: 3em; | ||
| } | ||
|
|
||
| #cityName { | ||
| font-size: larger; | ||
| } | ||
|
|
||
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.
Consider refactoring your class names so that they are lowercase and hyphenated between words