-
Notifications
You must be signed in to change notification settings - Fork 527
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
Sharks/Bahareh #17
Open
b-izad
wants to merge
2
commits into
AdaGold:main
Choose a base branch
from
b-izad:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Sharks/Bahareh #17
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,155 @@ | ||||
|
||||
const getLatAndLon = (city) => { | ||||
return axios | ||||
.get('http://127.0.0.1:5000/location', { | ||||
params: { | ||||
q: city, | ||||
}, | ||||
}) | ||||
.then((response) => { | ||||
console.log(response.data); | ||||
return { | ||||
lat: response.data[0].lat, | ||||
lon: response.data[0].lon, | ||||
}; | ||||
}) | ||||
.then((response)=>{ | ||||
console.log(response); | ||||
getWeatherKelvin(response.lat,response.lon) | ||||
}) | ||||
|
||||
.catch((error) => { | ||||
console.log('Error finding the latitude and longitude:', error.response); | ||||
}); | ||||
}; | ||||
|
||||
const getWeatherKelvin = (lat, lon) => { | ||||
return axios | ||||
.get('http://127.0.0.1:5000/weather', { | ||||
params: { | ||||
lat: lat, | ||||
lon: lon, | ||||
}, | ||||
}) | ||||
.then((response) => { | ||||
console.log(response); | ||||
return response.data.current.temp; | ||||
}) | ||||
.then((response)=>{ | ||||
console.log(response); | ||||
return Math.floor((response - 273.15) * 9/5 + 32) | ||||
}) | ||||
.then((response)=>{ | ||||
console.log(response); | ||||
state.temp=response | ||||
tempContainer.textContent=`${state.temp}`; | ||||
|
||||
}) | ||||
.catch((error) => { | ||||
console.log('Error finding the latitude and longitude:', error.response); | ||||
}); | ||||
}; | ||||
const saveCity=()=>{ | ||||
const cityName= document.getElementById('input').value; | ||||
state.city=cityName | ||||
console.log(state.city); | ||||
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. don't forget to take out debugging print statements like this out for final submissions
Suggested change
|
||||
getLatAndLon(state.city); | ||||
getWeatherKelvin(lat,lon); | ||||
|
||||
|
||||
|
||||
} | ||||
const realTimeButton = document.getElementById('real-time-temp'); | ||||
realTimeButton.addEventListener('click', saveCity); | ||||
|
||||
|
||||
// buttons for tempreture up and down | ||||
let btnAdd = document.querySelector('#increment'); | ||||
let btnSubstract = document.querySelector('#decrement') | ||||
let tempContainer=document.querySelector('#tempContainer') | ||||
|
||||
|
||||
const increment = ()=>{state.temp+=1; | ||||
tempContainer.textContent=`${state.temp}`; | ||||
changeLandscape(); | ||||
} | ||||
const decrement = () =>{state.temp-=1; | ||||
tempContainer.textContent=`${state.temp}`; | ||||
changeLandscape(); | ||||
} | ||||
|
||||
btnAdd.addEventListener('click',increment ); | ||||
btnSubstract.addEventListener('click',decrement ); | ||||
|
||||
|
||||
// Update name of the city | ||||
const updateCityName = () => { | ||||
let cityName = document.querySelector('#citynam'); | ||||
let inputName= document.querySelector('#input').value; | ||||
state.city = inputName; | ||||
cityName.textContent = state.city; | ||||
}; | ||||
const cityNameInput = document.getElementById('input'); | ||||
cityNameInput.addEventListener('input', updateCityName); | ||||
|
||||
// Reset name of the city | ||||
const state={city:'Tehran', | ||||
temp:70} | ||||
const reset = () => { | ||||
const cityName = document.getElementById('input'); | ||||
cityName.value = 'Tehran'; | ||||
updateCityName(); | ||||
}; | ||||
const resetButton = document.getElementById('reset'); | ||||
resetButton.addEventListener('click', reset); | ||||
|
||||
// With updated sky change the garden's sky | ||||
|
||||
const changeSky = () => { | ||||
let selectedSky = document.getElementById('skys'); | ||||
let skyOption = selectedSky.options[selectedSky.selectedIndex].text; | ||||
|
||||
let skyContainer=document.getElementById('garden-sky') | ||||
let currentSky ='🌈☀☀☀☀🌝🌝🌝🌝☀☀☀☀☀🌈' | ||||
if (skyOption === 'Sunny') { | ||||
currentSky = '☁️ ☁️ ☁️ ☀️ ☁️ ☁️'; | ||||
} else if (skyOption === 'Cloudy') { | ||||
currentSky = '☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️'; | ||||
} else if (skyOption === 'Rainy') { | ||||
currentSky = '🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧'; | ||||
} else if (skyOption === 'Snowy') { | ||||
currentSky = '🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨'; | ||||
} | ||||
skyContainer.textContent = currentSky; | ||||
}; | ||||
const changeUpSky = document.getElementById('skys'); | ||||
changeUpSky.addEventListener('change', changeSky); | ||||
|
||||
// With updated temp change the garden's landscape | ||||
|
||||
const changeLandscape = () => { | ||||
temp=state.temp | ||||
let tempContainer=document.getElementById('tempContainer') | ||||
let landscapeContainer=document.getElementById('ground') | ||||
let currentLandscape ='✨✨✨✨✨🌏🌏🌏🌏🌏' | ||||
if (temp>80) { | ||||
currentLandscape = "🌵__🐍_🦂_🌵🌵__🐍_🏜_🦂"; | ||||
tempContainer.style.backgroundColor = 'red'; | ||||
} else if (temp>=70) { | ||||
currentLandscape = "🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷" | ||||
tempContainer.style.backgroundColor = 'orange'; | ||||
} else if (temp>=60) { | ||||
currentLandscape = "🌾🌾_🍃_🪨__🛤_🌾🌾🌾_🍃" | ||||
tempContainer.style.backgroundColor = 'yellow'; | ||||
} else if (temp<=59) { | ||||
currentLandscape = "🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲" | ||||
tempContainer.style.backgroundColor = 'green'; | ||||
} | ||||
landscapeContainer.textContent = currentLandscape; | ||||
}; | ||||
const changeGround = document.getElementById('ground'); | ||||
changeGround.addEventListener('change', changeSky); | ||||
|
||||
|
||||
|
||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
* {background-color:cornsilk ; | ||
font-size: large;} | ||
|
||
.container { | ||
display: flex; | ||
flex-wrap: wrap; | ||
} | ||
|
||
.box { | ||
height: 50vh; | ||
flex-grow: 1; | ||
flex-shrink: 1; | ||
flex-basis: 20%; | ||
min-width: 300px; | ||
border-radius: 10%; | ||
/* padding:70 px 0; */ | ||
text-align: center; | ||
overflow-x: auto; | ||
border: 1px solid saddlebrown; | ||
box-sizing: border-box; | ||
background-color: salmon; | ||
|
||
} | ||
|
||
|
||
.header{margin:25%; | ||
background-color: grey; | ||
padding: 2%; | ||
} | ||
|
||
|
||
button{margin: 20%; | ||
padding: 10px; | ||
} | ||
|
||
|
||
/* #tempreture{background-color: aquamarine; | ||
} | ||
|
||
#garden-sky{background-color: yellow; | ||
} | ||
|
||
#garden-landscape{background-color: blue;} | ||
|
||
#city{background-color: violet;} | ||
|
||
#sky{background-color: bisque;} */ | ||
|
||
img{ | ||
display:block; | ||
margin:auto; | ||
height: 100%; | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Ooo nice job learning how to chain promises!