-
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
Maz + Kaliane Van #71
base: main
Are you sure you want to change the base?
Changes from all commits
8e084e3
fc21181
2cc2a70
c126ed8
eb6634a
46b06b4
28f5c42
4d2f23f
7d09b5f
1b1e016
9a75f09
cd6060d
393c5ea
9965e46
6e5dcef
f9e0e76
2ab4b47
0d20642
2b4d893
790fbb9
2114375
7a97d6e
07f23e8
d4f14f8
d3a2453
b6eca8b
9a88730
89e7037
e23f743
cf625f4
e6559d9
e63958d
283a4ce
664401d
93b4ab4
c6d9b54
8c9aa2d
35b0f6d
ea3cee3
3914ff7
51fa9d9
342d656
126d17a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
{ | ||
"dependencies": { | ||
"axios": "^1.2.1" | ||
} | ||
"axios": "^0.21.1" | ||
}, | ||
"name": "weather-report", | ||
"description": "## Skills Assessed", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
// `"use strict";` | ||
|
||
const state = { | ||
increaseTempButton: null, | ||
decreaseTempButton: null, | ||
tempNumberContainer: null, | ||
tempNumberClass: '', | ||
tempNumber: '', | ||
skyEmojiContainer: null, | ||
skyEmoji: '', | ||
landEmojiContainer: '', | ||
landEmoji: '', | ||
cityNameContainer: null, | ||
cityName: '', | ||
cityInput: '', | ||
realTempButton: null, | ||
SkyDropdown: null, | ||
lat: null, | ||
lon: null, | ||
}; | ||
|
||
const loadControls = () => { | ||
state.increaseTempButton = document.getElementById('increaseTempButton'); | ||
state.decreaseTempButton = document.getElementById('decreaseTempButton'); | ||
state.tempNumber = parseInt(document.getElementById('tempNumberContainer').innerText); | ||
state.tempNumberContainer = document.getElementById('tempNumberContainer'); | ||
state.tempNumberClass = document.getElementById('tempNumberContainer').className; | ||
state.skyEmojiContainer = document.getElementById('skyEmojiContainer'); | ||
state.skyEmoji = document.getElementById('skyEmojiContainer').innerText; | ||
state.landEmojiContainer = document.getElementById('landEmojiContainer'); | ||
state.landEmoji = document.getElementById('landEmojiContainer').innerText; | ||
state.cityNameContainer = document.getElementById('cityNameContainer'); | ||
state.cityName = document.getElementById('cityNameContainer').innerText; | ||
state.cityInput = document.getElementById('cityInput'); | ||
state.realTempButton = document.getElementById('realTempButton'); | ||
state.skyDropdown = document.getElementById('skyDropdown'); | ||
state.weatherCity = document.getElementById('weatherCity'); | ||
}; | ||
Comment on lines
+22
to
+38
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. Oh wow! I love this! This shows me you centering readability! Naming conventions like this make your code a lot more intuitive! |
||
|
||
const getTempColor = (tempNumber) => { | ||
let className = 'redTemp'; | ||
if (tempNumber >= 80) { | ||
className = 'redTemp'; | ||
} else if (tempNumber >= 70) { | ||
className = 'orangeTemp'; | ||
} else if (tempNumber >= 60) { | ||
className = 'yellowTemp'; | ||
} else if (tempNumber >= 50) { | ||
className = 'greenTemp'; | ||
} else if (tempNumber <= 49) { | ||
className = 'tealTemp'; | ||
} | ||
return className | ||
} | ||
|
||
const getLandscape = (temperature) => { | ||
if (temperature >= 80) { | ||
return "🌵__🐍_🦂_🌵🌵__🐍_🏜_🦂"; | ||
} else if (temperature >= 70) { | ||
return "🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷"; | ||
} else if (temperature >= 60) { | ||
return "🌾🌾_🍃_🪨__🛤_🌾🌾🌾_🍃"; | ||
} else { | ||
return "🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲"; | ||
} | ||
}; | ||
|
||
const getSky = (skyType) => { | ||
switch(skyType) { | ||
case 'sunny': | ||
return "☁️ ☁️ ☁️ ☀️ ☁️ ☁️"; | ||
case 'cloudy': | ||
return "☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️"; | ||
case 'rainy': | ||
return "🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧"; | ||
case 'snowy': | ||
return "🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨"; | ||
default: | ||
return ''; | ||
} | ||
}; | ||
|
||
const getRealTemp = async (locationName) => { | ||
const locationResp = await axios.get('http://localhost:5000/location',{ params: {q: locationName } }) | ||
|
||
const coords = [locationResp.data[0]['lat'], locationResp.data[0]['lon']] | ||
|
||
const weatherResponse = await getWeather(coords[0],coords[1]) | ||
|
||
return weatherResponse | ||
|
||
} | ||
Comment on lines
+83
to
+92
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. Okay |
||
|
||
const getWeather = async (lat,lon) => { | ||
const response = await axios | ||
.get('http://localhost:5000/weather',{ | ||
params: { | ||
lat: lat, | ||
lon: lon, | ||
units: 'imperial', | ||
}, | ||
}) | ||
|
||
state.tempNumber = response.data['main']['temp'] | ||
}; | ||
|
||
const registerEventHandlers = () => { | ||
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. ⭐️⭐️⭐️ |
||
state.increaseTempButton.addEventListener('click', () => { | ||
state.tempNumberContainer.innerText = ++state.tempNumber; | ||
state.tempNumberContainer.className = getTempColor(state.tempNumberContainer.innerText); | ||
state.landEmojiContainer.innerText = getLandscape(state.tempNumber); | ||
}); | ||
state.decreaseTempButton.addEventListener('click', () => { | ||
state.tempNumberContainer.innerText = --state.tempNumber; | ||
state.tempNumberContainer.className = getTempColor(state.tempNumber); | ||
state.landEmojiContainer.innerText = getLandscape(state.tempNumber); | ||
}); | ||
|
||
state.cityInput.addEventListener('input', () => { | ||
state.cityNameContainer.innerText = state.cityInput.value; | ||
state.weatherCity.innerText = state.cityInput.value; | ||
}); | ||
|
||
state.realTempButton.addEventListener('click', async () => { | ||
await getRealTemp(state.cityNameContainer.innerText) | ||
state.tempNumberContainer.innerText = state.tempNumber; | ||
state.tempNumberContainer.className = getTempColor(state.tempNumber); | ||
state.landEmojiContainer.innerText = getLandscape(state.tempNumber); | ||
}); | ||
state.skyDropdown.addEventListener('change', () => { | ||
state.skyEmojiContainer.innerText = getSky(state.skyDropdown.value); | ||
}); | ||
}; | ||
|
||
const onLoaded = () => { | ||
loadControls(); | ||
registerEventHandlers(); | ||
}; | ||
|
||
onLoaded(); | ||
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. I would suggest putting your document.addEventListener("DOMContentLoaded", function () {
loadControls()
registerEventHandlers()
} 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. 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! ⭐️ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
.redTemp { | ||
color: red; | ||
} | ||
|
||
.orangeTemp { | ||
color: orange; | ||
} | ||
|
||
.yellowTemp { | ||
color: yellow; | ||
} | ||
|
||
.greenTemp { | ||
color: green; | ||
} | ||
|
||
.tealTemp { | ||
color: teal; | ||
} | ||
|
||
#landscapeEmojiDiv { | ||
font-size: 24px; | ||
line-height: 1.5; | ||
margin-top: 20px; | ||
white-space: pre-wrap; | ||
} | ||
|
||
.cityDisplay { | ||
background-color: red; | ||
/* padding; */ | ||
display: flex; | ||
flex-direction: row; | ||
gap: 1rem; | ||
} | ||
|
||
.container { | ||
display: grid; | ||
grid-template-columns: repeat(2, 1fr); | ||
grid-template-rows: repeat(4, 1fr); | ||
grid-column-gap: 50px; | ||
grid-row-gap: 50px; | ||
} | ||
|
||
.header { grid-area: 1 / 1 / 2 / 2; } | ||
|
||
.child { | ||
background-color: aliceblue; | ||
} | ||
|
||
.div2 { grid-area: 2 / 2 / 5 / 3; } |
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!