-
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: Megan & Jay #61
base: main
Are you sure you want to change the base?
Changes from all commits
345754d
636c0bc
598ec2d
05989c1
aab2cf8
57648ca
cf1d3b8
25f74a0
d7d7b6e
7654346
f51af66
b68afa9
e58c9ae
0495580
6454f4f
1d8df3f
c8fefdb
83f9439
b88683b
d4eecf0
6389dc3
516c607
78ba8af
9ff58be
f71583d
3462121
92a3fbd
a4a4a80
d00f860
e35ae5c
c3ec424
988cc1d
1814863
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,183 @@ | ||
const state ={ | ||
temp: 0, | ||
number: document.getElementById("temperature-now"), | ||
} | ||
|
||
const upButton = document.getElementById("up-button"); | ||
const downButton = document.getElementById("button-down"); | ||
const tempButton = document.getElementById("get-temp") | ||
// let number = document.getElementById("temperature-now"); | ||
// let temp = parseFloat(number.innerText); | ||
state.temp = parseFloat(state.number.innerText); | ||
const weatherGarden = document.getElementById('weather-garden'); | ||
const weatherEmojis = document.getElementById('weather-emojis'); | ||
const cityDisplay = document.getElementById("city-display") | ||
const cityId = document.getElementById("city-input") | ||
const skyOptions = document.getElementById('change-sky'); | ||
const skyEmojis = document.getElementById('chosen-sky-emojis'); | ||
const resetBtn = document.getElementById('resetbtn'); | ||
Comment on lines
+6
to
+18
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. 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 display() { | ||
cityDisplay.innerText = cityId.value; | ||
} | ||
|
||
// console.log('curret temp', number.innerText); | ||
|
||
const incrementNum = () => { | ||
state.number.innerText = state.temp++; | ||
} | ||
// color changing function | ||
const colorTemp = () => { | ||
|
||
if (state.temp < 49){ | ||
state.number.style.color = "teal"; | ||
} | ||
else if (state.temp < 59){ | ||
state.number.style.color = "green"; | ||
} | ||
else if (state.temp < 69){ | ||
state.number.style.color = "yellow"; | ||
} | ||
else if (state.temp < 79){ | ||
state.number.style.color = "orange"; | ||
} | ||
else { | ||
|
||
state.number.style.color = "red"; | ||
} | ||
|
||
} | ||
|
||
skyOptions.addEventListener('change', () => { | ||
const skyValue = document.getElementById('change-sky').value; | ||
if (skyValue == 'sunny') { | ||
skyEmojis.innerText = '☀️☀️ ☁️ ☀️☁️ ☀️ ☁️☀️☀️'; | ||
} else if (skyValue =='cloudy') { | ||
skyEmojis.innerText = '☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️'; | ||
} else if (skyValue == 'rainy') { | ||
skyEmojis.innerText = '🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧'; | ||
} else if (skyValue == 'snowy') { | ||
skyEmojis.innerText = '🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨'; | ||
} else { | ||
skyEmojis.innerText = ''; | ||
} | ||
}) | ||
|
||
|
||
const weatherGardenChanges = () => { | ||
|
||
if (state.temp < 59){ | ||
weatherGarden.style.backgroundColor = "green"; | ||
weatherEmojis.innerHTML = "🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲" | ||
} | ||
else if (state.temp < 69){ | ||
weatherGarden.style.backgroundColor = "yellow"; | ||
weatherEmojis.innerHTML = "🌾🌾_🍃_🪨__🛤_🌾🌾🌾_🍃" | ||
} | ||
else if (state.temp < 79){ | ||
weatherGarden.style.backgroundColor = "orange"; | ||
weatherEmojis.innerHTML = "🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷" | ||
} | ||
else { | ||
weatherGarden.style.backgroundColor = "red"; | ||
weatherEmojis.innerHTML = "🌵__🐍_🦂_🌵🌵__🐍_🏜_🦂" | ||
} | ||
|
||
} | ||
|
||
|
||
upButton.addEventListener("click", () => { | ||
console.log(state.temp); | ||
incrementNum(); | ||
colorTemp(state.temp); | ||
weatherGardenChanges(state.temp); | ||
}); | ||
|
||
|
||
const decrementNum = () => { | ||
state.number.innerText = state.temp--; | ||
} | ||
|
||
downButton.addEventListener("click", () => { | ||
console.log(state.temp); | ||
decrementNum() | ||
colorTemp(state.temp) | ||
weatherGardenChanges(state.temp); | ||
}); | ||
|
||
const getLanLon = (city) => { | ||
return axios.get(`http://localhost:5000/location?q=${city}`) | ||
.then(response => { | ||
let lat = response.data[0].lat | ||
let lon = response.data[0].lon | ||
console.log(response.data[0].display_name) | ||
return [lat, lon] | ||
}) | ||
.catch(error => { | ||
console.log(error) | ||
}) | ||
} | ||
Comment on lines
+113
to
+124
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. Here's an alternative to promise chaining! You can use the 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)
}
}; |
||
|
||
const getWeather = (coords) => { | ||
let lat = coords[0] | ||
let lon = coords[1] | ||
return axios.get(`http://localhost:5000/weather?lat=${lat}&lon=${lon}`) | ||
.then(response => { | ||
console.log(response.data.main.temp) | ||
return response.data.main.temp | ||
}).catch(error => { | ||
console.log(error) | ||
}) | ||
} | ||
|
||
// should this be async-await so that I can change the innerTEXT? probably yes! (unless I can use .then to change the innerText (lol)) | ||
|
||
// tempButton.addEventListener("click", () => { | ||
// const cityNow = cityDisplay.innerText; | ||
// console.log(cityNow) | ||
// getLanLon(cityNow).then(resp => getWeather(resp)) | ||
|
||
// }) | ||
|
||
const kelvinToFarenheit = (k) => { | ||
return Math.floor((k - 273.15) * 9/5 + 32); | ||
} | ||
|
||
tempButton.addEventListener("click", () => { | ||
const cityNow = cityDisplay.innerText; | ||
console.log(cityNow) | ||
getLanLon(cityNow) | ||
.then(resp => getWeather(resp)) | ||
.then(weather => { | ||
state.temp = kelvinToFarenheit(weather); | ||
state.number.innerText = state.temp; | ||
colorTemp(state.temp); | ||
weatherGardenChanges(); | ||
}) | ||
|
||
|
||
}); | ||
|
||
|
||
document.addEventListener("load", colorTemp(state.temp)) | ||
document.addEventListener("load", weatherGardenChanges()) | ||
|
||
// resetBtn.addEventListener('click', () => { | ||
// const cityInput = document.getElementById('city-input'); | ||
// console.log('click') | ||
// cityInput.reset() | ||
// }) | ||
|
||
|
||
// document.getElementById("myForm").reset() | ||
|
||
|
||
resetBtn.addEventListener("click",() =>{ | ||
cityDisplay.innerText = ""; | ||
cityId.value = "" | ||
} ) | ||
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,146 @@ | ||
body { | ||
background-color: #1b69f9; | ||
font-family: Rubik, sans-serif; | ||
display: flex; | ||
flex-direction:row; | ||
flex-wrap: wrap; | ||
} | ||
|
||
header { | ||
width: 100vw; | ||
height: 100px; | ||
text-align: center; | ||
color: #ffffff; | ||
} | ||
|
||
.left-side-container { | ||
width: 35vw; | ||
} | ||
|
||
.right-side-container { | ||
width: 61vw; | ||
/* border: solid red; */ | ||
display: flex; | ||
justify-content: center; | ||
text-align: center; | ||
align-items: center; | ||
} | ||
|
||
.right-side-container h2 { | ||
color:#ffffff; | ||
} | ||
|
||
.temperature-section { | ||
height: 200px; | ||
width: 100%; | ||
background-color: #ffffff; | ||
border-radius: 10px; | ||
display: flex; | ||
flex-wrap: wrap; | ||
} | ||
|
||
.temperature-section h3{ | ||
text-align: center; | ||
width: 100%; | ||
height: 1px; | ||
} | ||
|
||
.temp-btn-sect { | ||
margin: 0px 30px; | ||
/* padding: 0px 0px 0px 10px; */ | ||
font-size: 25px; | ||
} | ||
|
||
#get-temp { | ||
margin: 40px 0px; | ||
padding: 10px 5px; | ||
background-color: #1b69f9; | ||
color:#ffffff; | ||
border-radius: 10px; | ||
border: none; | ||
font-size: 16px; | ||
} | ||
|
||
.sky-menu { | ||
background-color: #ffffff; | ||
border-radius: 10px; | ||
height: 80px; | ||
width: auto; | ||
margin: 20px 0px; | ||
padding: 30px; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
text-align: center; | ||
} | ||
|
||
|
||
#change-sky { | ||
width: 20vw; | ||
height: auto; | ||
margin: 50px; | ||
text-align: center; | ||
} | ||
|
||
.city-choice { | ||
background-color: #ffffff; | ||
border-radius: 10px; | ||
text-align: center; | ||
height: 140px; | ||
width: auto; | ||
} | ||
|
||
.city-choice h3 { | ||
padding: 20px 0px 0px 0px; | ||
font-size: 20px; | ||
} | ||
|
||
#city-input { | ||
border-radius: 5px; | ||
} | ||
|
||
#resetbtn { | ||
background-color: #1b69f9; | ||
border-radius: 10px; | ||
border: none; | ||
padding: 10px 20px 10px 20px; | ||
margin: 0px 0px 0px 10px; | ||
color: #ffffff; | ||
|
||
} | ||
|
||
#weather-garden { | ||
/* border: solid black; */ | ||
border-radius: 10px; | ||
height: 200px; | ||
width: 40vw;; | ||
background-color: #ddffff; | ||
} | ||
|
||
#weather-garden p { | ||
font-size: 25px;; | ||
} | ||
|
||
#chosen-sky-emojis { | ||
justify-content: center; | ||
height: 40px; | ||
width: auto; | ||
/* border: solid green; */ | ||
padding-top: 30px; | ||
} | ||
|
||
#weather-emojis { | ||
width: auto; | ||
height: 40px; | ||
margin: 70px 0px 0px 0px; | ||
} | ||
|
||
|
||
|
||
footer { | ||
border-top: solid #ffffff; | ||
width: 100vw; | ||
height: 10vh; | ||
margin: 50px 50px; | ||
text-align: center; | ||
} |
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!