-
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
Cedar - Kristin L #57
base: main
Are you sure you want to change the base?
Changes from all commits
bd2d955
3783f53
d5c1954
2289eb4
94659de
a94ddef
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,104 @@ | ||
const tempDegree = document.querySelector('#temperatureDegree'); | ||
const landscape = document.querySelector('#landscape'); | ||
const selectedSky = document.querySelector('#skyEmojis'); | ||
const gardenBackground = document.querySelector('#weatherGardenContainer'); | ||
const inputCity = document.querySelector('#inputCity'); | ||
const displayCity = document.getElementById('cityNameDisplay'); | ||
const resetButton = document.getElementById('resetCity'); | ||
|
||
const state = { | ||
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. Nice use of the state object! |
||
tempNumber: 80, | ||
skyState: ' ☁️ ☁️ ☀️ ☁️ ☁️ ☀️ ☀️ ☀️ ☁️ ☀️☀️ ☀️ ☁️ ☀️', | ||
gardenColor: '#D6FFFF', | ||
}; | ||
|
||
// Temperature up and down buttons | ||
const increaseTemperature = () => { | ||
state.tempNumber += 1; | ||
tempDegree.textContent = `${state.tempNumber}`; | ||
changeTheme(); | ||
}; | ||
|
||
const decreaseTemperature = () => { | ||
state.tempNumber -= 1; | ||
tempDegree.textContent = `${state.tempNumber}`; | ||
changeTheme(); | ||
}; | ||
|
||
//Landscape and weather garden background color | ||
const changeTheme = () => { | ||
// if different ranges, change color | ||
if (state.tempNumber >= 80) { | ||
tempDegree.style.color = '#EA0009'; | ||
landscape.textContent = '🌵__🐍_🦂_🌵🌵__🐍_🏜_🦂🌵__🐍_🏜_🦂'; | ||
} else if (state.tempNumber >= 70 && state.tempNumber <= 79) { | ||
tempDegree.style.color = '#F0940A'; | ||
landscape.textContent = '🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷🌿_☘️🌱_🌻🌷'; | ||
} else if (state.tempNumber >= 60 && state.tempNumber <= 69) { | ||
tempDegree.style.color = '#F4D10A'; | ||
landscape.textContent = '🌾🌾_🍃_🪨__🛤_🌾🌾🌾_🍃__🛤_🌾🌾🌾_🍃'; | ||
} else if (state.tempNumber >= 50 && state.tempNumber <= 59) { | ||
tempDegree.style.color = '#1F7001'; | ||
landscape.textContent = '🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲🍂🌲🍁🌲🌲⛄️🍂'; | ||
} else { | ||
tempDegree.style.color = '#256D6C'; | ||
landscape.textContent = | ||
'⛄️⛄️🌲⛄️⛄️🌲⛄️⛄️🌲⛄️🌲⛄️🌲⛄️🌲⛄️⛄️🌲⛄️🌲⛄️'; | ||
} | ||
}; | ||
|
||
//City name reset button | ||
const updateCity = (event) => { | ||
displayCity.textContent = event.target.value; | ||
}; | ||
|
||
//reset City | ||
const resetCity = (event) => { | ||
event.target.value = 'Seattle'; | ||
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. Rather than setting the |
||
displayCity.textContent = event.target.value; | ||
}; | ||
|
||
//register event handlers | ||
const registerEventHandlers = () => { | ||
//up button | ||
const tempUpButton = document.querySelector('#tempButtonUp'); | ||
tempUpButton.addEventListener('click', increaseTemperature); | ||
//down button | ||
const tempDownButton = document.querySelector('#tempButtonDown'); | ||
tempDownButton.addEventListener('click', decreaseTemperature); | ||
|
||
//City input | ||
inputCity.addEventListener('change', updateCity); | ||
|
||
//reset city | ||
resetButton.addEventListener('click', resetCity); | ||
|
||
//wave 3: onchangehandler | ||
const skyDropdown = document.querySelector('.sky'); | ||
skyDropdown.addEventListener('change', (event) => { | ||
if (event.target.value === 'sunny') { | ||
selectedSky.textContent = ' ☁️ ☁️ ☀️ ☁️ ☁️ ☀️ ☀️ ☀️ ☁️ ☀️☀️ ☀️ ☁️ ☀️'; | ||
gardenBackground.style.backgroundColor = '#D6FFFF'; | ||
} else if (event.target.value === 'cloudy') { | ||
selectedSky.textContent = '☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️🌤 ☁️ ☁️☁️'; | ||
gardenBackground.style.backgroundColor = '#C9C9C9'; | ||
} else if (event.target.value === 'rainy') { | ||
selectedSky.textContent = '🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧🌧🌈⛈🌧'; | ||
gardenBackground.style.backgroundColor = '#9FCFE0'; | ||
} else if (event.target.value === 'snowy') { | ||
selectedSky.textContent = '🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨🌨❄️❄️🌨🌨'; | ||
gardenBackground.style.backgroundColor = '#A1B6D6'; | ||
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. Directly applying styles works and is a valid approach. You may also consider applying a class name to keep the styles in the stylesheet. |
||
} | ||
Comment on lines
+78
to
+91
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. To enhance readability, you might consider refactoring and moving the sky/color change functionality into a named function that's passed here as a callback function (rather than an anonymous function) |
||
}); | ||
}; | ||
|
||
const defaultSetup = () => { | ||
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. Nice work encapsulating this default set-up here! |
||
tempDegree.textContent = `${state.tempNumber}`; | ||
selectedSky.textContent = `${state.skyState}`; | ||
gardenBackground.style.backgroundColor = `${state.gardenColor}`; | ||
registerEventHandlers(); | ||
changeTheme(); | ||
}; | ||
//execute registerEventHandlers | ||
//runs code once DOM is ready. DOM isn't fully loaded, eventhandlers might not exist yet. Ex: buttoon on line 35 | ||
document.addEventListener('DOMContentLoaded', defaultSetup); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
@import url('https://fonts.googleapis.com/css2?family=Bevan&family=Cinzel+Decorative:wght@700&family=Knewave&display=swap'); | ||
@import url('https://fonts.googleapis.com/css2?family=Bevan&family=Cinzel+Decorative:wght@700&family=Goudy+Bookletter+1911&family=Knewave&display=swap'); | ||
@import url('https://fonts.googleapis.com/css2?family=Bevan&family=Bungee+Shade&family=Cinzel+Decorative:wght@700&family=Galada&family=Goudy+Bookletter+1911&family=Knewave&display=swap'); | ||
@import url('https://fonts.googleapis.com/css2?family=Bevan&family=Bungee+Shade&family=Cinzel+Decorative:wght@700&family=Galada&family=Goudy+Bookletter+1911&family=Knewave&family=Pompiere&display=swap'); | ||
|
||
/* Arrows */ | ||
.arrow { | ||
border: solid black; | ||
border-width: 0 3px 3px 0; | ||
display: inline-block; | ||
padding: 3px; | ||
} | ||
|
||
.up { | ||
transform: rotate(-135deg); | ||
-webkit-transform: rotate(-135deg); | ||
} | ||
|
||
.down { | ||
transform: rotate(45deg); | ||
-webkit-transform: rotate(45deg); | ||
} | ||
|
||
/* Text Styles */ | ||
|
||
#cityNameDisplay { | ||
color:mediumvioletred; | ||
font-weight: 900; | ||
} | ||
|
||
.title { | ||
font-family: 'Cinzel Decorative', cursive; | ||
color: white; | ||
font-size: 2.1em; | ||
} | ||
|
||
#subtitle { | ||
font-family: 'Goudy Bookletter 1911', serif; | ||
color: rgb(55, 46, 46); | ||
font-size: 1.5em; | ||
} | ||
|
||
.item-titles { | ||
font-family: 'Galada', cursive; | ||
color:rgb(85, 71, 71); | ||
font-size: 1.7em; | ||
} | ||
|
||
header { | ||
text-align: center; | ||
} | ||
|
||
.footer { | ||
text-align: center; | ||
font-family: 'Pompiere', cursive; | ||
font-weight: bold; | ||
} | ||
|
||
body { | ||
background-color: #f6f0c4; | ||
background-image: linear-gradient(315deg, #f6f0c4 0%, #d99ec9 74%); | ||
} | ||
|
||
/* Layout */ | ||
|
||
.content-wrapper { | ||
margin: 5px; | ||
} | ||
|
||
.temp-wrapper { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-evenly; | ||
} | ||
|
||
.button-wrapper { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-around; | ||
} | ||
|
||
.items-wrapper { | ||
display: grid; | ||
grid-template-columns: 1fr 1fr 1fr; | ||
align-content: center; | ||
padding: 20px; | ||
margin: 5px; | ||
} | ||
|
||
.item-wrapper { | ||
position: relative; | ||
text-align: center; | ||
outline: .5px solid grey; | ||
padding: 5px; | ||
margin: 5px 15px; | ||
border-radius: 10%; | ||
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2); | ||
} | ||
|
||
#weatherGardenContainer { | ||
grid-column-start: 1; | ||
grid-column-end: 4; | ||
width: 60%; | ||
border-radius: 10%; | ||
margin: 5px auto; | ||
} | ||
|
||
#skyEmojis { | ||
margin-bottom: 40px; | ||
font-size: 1.5em; | ||
} | ||
|
||
#landscape { | ||
margin-top: 10px; | ||
font-size: 1.5em; | ||
} | ||
|
||
#temperatureDegree { | ||
font-size: 2em; | ||
margin-bottom: 0 auto; | ||
} | ||
|
||
|
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.
You might consider making the
temperatureContainer
,cityNameContainer
,skyContainer
, andweatherGardenContainer
section elements