-
Notifications
You must be signed in to change notification settings - Fork 100
Panthers Jan L. #74
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?
Panthers Jan L. #74
Changes from all commits
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "dependencies": { | ||
| "axios": "^0.27.2" | ||
| "axios": "^1.2.1" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| // import axios from 'axios'; | ||
| 'use strict'; | ||
|
|
||
| const state = { | ||
| temp: 32, | ||
| }; | ||
|
|
||
| const plusClickCount = () => { | ||
| const plusContainer = document.getElementById('Temperature'); | ||
| state.temp += 1; | ||
| plusContainer.textContent = state.temp; | ||
| changeColor(); | ||
| }; | ||
|
|
||
| const minusClickCount = () => { | ||
| const minusContainer = document.getElementById('Temperature'); | ||
| state.temp -= 1; | ||
| minusContainer.textContent = state.temp; | ||
| changeColor(); | ||
| }; | ||
| //making text color different | ||
| const changeColor = () => { | ||
| const tempColor = document.querySelector('#Temperature'); | ||
| const newLS = document.getElementById('newLandscape'); | ||
|
|
||
| if (state.temp < 49) { | ||
| tempColor.style.color = 'teal'; | ||
| newLS.src = `assets/cold.jpeg`; | ||
| } else if (state.temp >= 50 && state.temp < 59) { | ||
| tempColor.style.color = 'green'; | ||
| newLS.src = `assets/cool.jpeg`; | ||
| } else if (state.temp >= 60 && state.temp < 69) { | ||
| tempColor.style.color = 'yellow'; | ||
| newLS.src = `assets/warm.jpeg`; | ||
| } else if (state.temp >= 70 && state.temp < 79) { | ||
| tempColor.style.color = 'orange'; | ||
| newLS.src = `assets/beach.jpeg`; | ||
| } else if (state.temp >= 80) { | ||
| tempColor.style.color = 'red'; | ||
| newLS.src = `assets/hot1.jpeg`; | ||
| } | ||
| }; | ||
|
|
||
| //wave 4 axios call | ||
| const realTimeClick = () => { | ||
| let query = input.value; | ||
| // displayTemp(); | ||
| findLocationWeather(query); | ||
| }; | ||
|
|
||
| const displayTemp = () => { | ||
| let tempContainer = document.getElementById('Temperature'); | ||
| tempContainer.textContent = state.temp; | ||
| }; | ||
|
|
||
| const findLocationWeather = (query) => { | ||
| axios | ||
| .get('http://127.0.0.1:5000/location', { | ||
| params: { | ||
| format: 'json', | ||
| q: query, | ||
| }, | ||
| }) | ||
| .then((response) => { | ||
| let latitude = response.data[0].lat; | ||
| let longitude = response.data[0].lon; | ||
| axios | ||
| .get('http://127.0.0.1:5000/weather', { | ||
| params: { | ||
| format: 'json', | ||
| lat: latitude, | ||
| lon: longitude, | ||
| }, | ||
| }) | ||
| .then((response) => { | ||
| console.log('success in findWeather!', response.data); | ||
| const currentTemp = Math.floor( | ||
| (Number(response.data.main.temp) - 273.15) * 1.8 + 32 | ||
| ); | ||
| state.temp = currentTemp; | ||
| changeColor(); | ||
| displayTemp(); | ||
| }) | ||
| .catch((error) => { | ||
| console.log('error in findweather!', error); | ||
| }); | ||
| }) | ||
| .catch((error) => { | ||
| console.log('error!', error); | ||
| }); | ||
| }; | ||
|
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. You handled this nested promise chaining very well! However there is a way we can make this code more concise! Making use of the const findLocation = async (query) => {
try {
const coordinates = await axios.get('http://127.0.0.1:5000/location', {
params: {
q: query,
format: 'json',
}})
let latitude = coordinates.data[0].lat;
let longitude = coordinates.data[0].lon;
findWeather(latitude, longitude)
} catch (err) {
console.log(err)
}
} Essentially, the |
||
|
|
||
| //wave 5 | ||
|
|
||
| const selectSky = document.querySelector('.sky'); | ||
|
|
||
| selectSky.addEventListener('change', (event) => { | ||
| const result = document.querySelector('.result'); | ||
| result.textContent = `The sky is ${event.target.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. I love this use of the event object! |
||
| }); | ||
|
|
||
| //wave 3 update text | ||
| const input = document.querySelector('input'); | ||
| const log = document.getElementById('values'); | ||
|
|
||
| input.addEventListener('input', updateValue); | ||
|
|
||
| function updateValue(e) { | ||
| log.textContent = e.target.value; | ||
| } | ||
| //wave 6 | ||
| const resetCity = () => { | ||
| input.value = ''; | ||
| log.textContent = ''; | ||
| }; | ||
|
|
||
| const registerEventHandlers = () => { | ||
| const hotterButton = document.getElementById('plusButton'); | ||
| hotterButton.addEventListener('click', plusClickCount); | ||
| const coolerButton = document.getElementById('minusButton'); | ||
| coolerButton.addEventListener('click', minusClickCount); | ||
| let realTimeButton = document.getElementById('realTimeButton'); | ||
| realTimeButton.addEventListener('click', realTimeClick); | ||
| const reset = document.getElementById('resetButton'); | ||
| reset.addEventListener('click', resetCity); | ||
| }; | ||
|
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. ✨✨✨ |
||
|
|
||
| document.addEventListener('DOMContentLoaded', registerEventHandlers); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| body { | ||
| display: grid; | ||
| grid-template-columns: 1fr 2fr; | ||
| grid-template-rows: auto auto ; | ||
| grid-gap: 1rem; | ||
| font-family: "Rubik", sans-serif; | ||
| font-size: 18px; | ||
| background-color: #a2b8df; | ||
| margin: 5rem; | ||
| } | ||
|
|
||
| .temp_section,.button_section { | ||
| background-color: hwb(102 67% 17%); | ||
| border: none; | ||
| color: green; | ||
| padding: 15px 32px; | ||
| text-align: center; | ||
| text-decoration: none; | ||
| display: inline-block; | ||
| font-size: 16px; | ||
| border-radius: 10px; | ||
| grid-column: 1; | ||
| grid-row:1 | ||
| } | ||
| .sky_section { | ||
| background-color: hwb(102 67% 17%); | ||
| border: none; | ||
| color: green; | ||
| padding: 15px 32px; | ||
| text-align: center; | ||
| text-decoration: none; | ||
| display: inline-block; | ||
| font-size: 16px; | ||
| border-radius: 10px; | ||
| grid-column: 1; | ||
| grid-row:2 | ||
| } | ||
| img{ | ||
| width: 500px; | ||
| } | ||
| .landscape{ | ||
| grid-column: 2; | ||
| grid-row:1/span 2 | ||
| } |
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.
The logic here is correct, the only thing that is that you didn't need to put
state.temp >= 50 && state.temp < 59and then(state.temp >= 60 && state.temp < 69). You could just dostate.temp > 50andstate.temp > 60. These take care of the range between these two numbers.