-
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
Ruby Kimberly & Sage #51
base: main
Are you sure you want to change the base?
Changes from all commits
97f9762
9612a8e
23ef80d
f214ae1
fd929d4
a9c004a
cd632d9
5dfb81a
926bab3
e513f7e
d12cd67
2186232
1856f1c
afac519
2c85658
45c57ff
dc448e8
3bc37e4
759c5fb
f442ecc
523235a
82afeec
cbb7b8e
701f50e
ef0b939
f215d58
3724992
6093fb2
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,185 @@ | ||
|
||
const state = { | ||
city: 'Seattle', | ||
lat: 47.6038321, | ||
long: -122.3300624, | ||
temp: 70, | ||
}; | ||
|
||
const convertKToF = (temp) => { | ||
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. Excellent! |
||
return (temp - 273.15) * (9 / 5) + 32; | ||
}; | ||
|
||
const getWeather = () => { | ||
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. Excellent! |
||
axios | ||
.get('http://127.0.0.1:5000/weather', { | ||
params: { | ||
lat: state.lat, | ||
lon: state.long, | ||
}, | ||
}) | ||
.then((response) => { | ||
const weather = response.data; | ||
state.temp = Math.round(convertKToF(weather.main.temp)); | ||
formatTempAndGarden(); | ||
}) | ||
.catch((error) => { | ||
console.log('Could not retrieve the weather:') | ||
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. Minor nitpick, but it seems you meant to include printing the error, but didn't! |
||
}); | ||
}; | ||
|
||
const getCoordinates = async () => { | ||
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. Generally, if you add |
||
axios | ||
.get('http://127.0.0.1:5000/location', { | ||
params: { | ||
q: state.city, | ||
}, | ||
}) | ||
.then((response) => { | ||
state.lat = response.data[0].lat; | ||
state.long = response.data[0].lon; | ||
getWeather(); | ||
}) | ||
.catch((error) => { | ||
console.log('Could not find latitute and longitude:', error.response); | ||
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 believe errors don't have a response, you would just print the error directly. |
||
}); | ||
}; | ||
|
||
const updateCityName = () => { | ||
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. Excellent! |
||
const inputName = document.getElementById("cityNameInput").value; | ||
const headerCityName = document.getElementById("headerCityName"); | ||
state.city = inputName; | ||
headerCityName.textContent = state.city; | ||
}; | ||
|
||
const resetCityName = () => { | ||
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. Excellent! |
||
const cityNameInput = document.getElementById("cityNameInput"); | ||
cityNameInput.value = 'Seattle'; | ||
updateCityName(); | ||
}; | ||
|
||
const formatSky = () => { | ||
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. Excellent! |
||
const skies = { | ||
sunny: "☁️ ☁️ ☁️ ☀️ ☁️ ☁️", | ||
cloudy: "☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️", | ||
rainy: "🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧", | ||
snowy: "🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨" | ||
}; | ||
const inputSky = document.getElementById('skySelect').value; | ||
const skyBox = document.getElementById('sky'); | ||
let sky = ''; | ||
let skyColor = ''; | ||
|
||
if (inputSky === 'Sunny') { | ||
sky = skies.sunny; | ||
skyColor = 'sunny'; | ||
} else if (inputSky === 'Cloudy') { | ||
sky = skies.cloudy; | ||
skyColor = 'cloudy'; | ||
} else if (inputSky === 'Rainy') { | ||
sky = skies.rainy; | ||
skyColor = 'rainy'; | ||
} else if (inputSky === 'Snowy') { | ||
sky = skies.snowy; | ||
skyColor = 'snowy'; | ||
} | ||
|
||
skyBox.textContent = sky; | ||
const gardenContent = document.getElementById('gardenContent'); | ||
gardenContent.classList = `garden__content ${skyColor}`; | ||
} | ||
|
||
const formatTempAndGarden = () => { | ||
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. Excellent! |
||
const landscapes = { | ||
hot: "🌵__🐍_🦂_🌵🌵__🐍_🏜_🦂", | ||
warm: "🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷", | ||
cool: "🌾🌾_🍃_🪨__🛤_🌾🌾🌾_🍃", | ||
cold: "🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲" | ||
}; | ||
let temp = state.temp; | ||
let color = 'green'; | ||
let landscape = landscapes.warm; | ||
|
||
if (temp >= 100) { | ||
color = 'red'; | ||
landscape = landscapes.hot; | ||
} else if (temp >= 95) { | ||
color = 'orangered'; | ||
landscape = landscapes.hot; | ||
} else if (temp >= 86) { | ||
color = 'orange'; | ||
landscape = landscapes.hot; | ||
} else if (temp >= 77) { | ||
color = 'green'; | ||
landscape = landscapes.warm; | ||
} else if (temp >= 68) { | ||
color = 'darkgreen'; | ||
landscape = landscapes.warm; | ||
} else if (temp >= 59) { | ||
color = 'teal'; | ||
landscape = landscapes.cool; | ||
} else if (temp >= 50) { | ||
color = 'cornflowerblue'; | ||
landscape = landscapes.cool; | ||
} else if (temp >= 41) { | ||
color = 'steelblue'; | ||
landscape = landscapes.cold; | ||
} else if (temp >= 32) { | ||
color = 'royalblue'; | ||
landscape = landscapes.cold; | ||
} else if (temp >= 23) { | ||
color = 'darkblue'; | ||
landscape = landscapes.cold; | ||
} else if (temp >= 14) { | ||
color = 'darkslateblue'; | ||
landscape = landscapes.cold; | ||
} else if (temp >= 5) { | ||
color = '#424040'; | ||
landscape = landscapes.cold; | ||
} else { | ||
color = 'black'; | ||
landscape = landscapes.cold; | ||
} | ||
|
||
const temperature = document.getElementById('tempValue'); | ||
const newLandscape = document.getElementById('landscape'); | ||
temperature.style.color = color; | ||
temperature.textContent = String(state.temp); | ||
newLandscape.textContent = landscape; | ||
}; | ||
|
||
const increaseTemp = () => { | ||
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. Excellent! |
||
state.temp++; | ||
formatTempAndGarden(); | ||
}; | ||
|
||
const decreaseTemp = () => { | ||
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. Excellent! |
||
state.temp--; | ||
formatTempAndGarden(); | ||
}; | ||
|
||
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. Excellent! |
||
formatTempAndGarden(); | ||
const currentTempBtn = document.getElementById('currentTempBtn'); | ||
currentTempBtn.addEventListener('click', getCoordinates); | ||
|
||
const increaseTempBtn = document.getElementById('increaseTempBtn'); | ||
increaseTempBtn.addEventListener('click', increaseTemp); | ||
|
||
const decreaseTempBtn = document.getElementById('decreaseTempBtn'); | ||
decreaseTempBtn.addEventListener('click', decreaseTemp); | ||
|
||
updateCityName(); | ||
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. This function call is not necessary when the page first loads since it's the one that needs to be called when users are typing something in to the search bar. |
||
const cityNameInput = document.getElementById('cityNameInput'); | ||
cityNameInput.addEventListener('input', updateCityName); | ||
|
||
const cityNameResetBtn = document.getElementById('cityNameReset'); | ||
cityNameResetBtn.addEventListener('click', resetCityName); | ||
cityNameResetBtn.addEventListener('click', getCoordinates); | ||
|
||
formatSky(); | ||
const skySelect = document.getElementById('skySelect'); | ||
skySelect.addEventListener('change', formatSky); | ||
}; | ||
|
||
document.addEventListener('DOMContentLoaded', registerEventHandlers); |
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.
😂 Excellent!