-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Completes wave 02. Changes pics and temp color dynamically
- Loading branch information
1 parent
dd0b5c9
commit f75d797
Showing
7 changed files
with
109 additions
and
7 deletions.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1 +1,77 @@ | ||
'use strict'; | ||
|
||
const state = { | ||
temp: 80, | ||
tempColor: 'red', | ||
tempBackground: 'url(../src/images/sunny.png)', | ||
}; | ||
|
||
const temp = document.getElementById('temp'); | ||
temp.textContent = state.temp + '°'; | ||
temp.style.color = state.tempColor; | ||
|
||
const backColor = document.getElementsByTagName('main')[0]; | ||
backColor.style.backgroundImage = state.tempBackground; | ||
|
||
const changetempColor = () => { | ||
if (state.temp >= 80) { | ||
state.tempColor = 'red'; | ||
temp.style.color = state.tempColor; | ||
} else if (state.temp > 69 && state.temp < 80) { | ||
state.tempColor = 'orange'; | ||
temp.style.color = state.tempColor; | ||
} else if (state.temp < 70 && state.temp > 59) { | ||
state.tempColor = 'yellow'; | ||
temp.style.color = state.tempColor; | ||
} else if (state.temp < 60 && state.temp > 49) { | ||
state.tempColor = 'green'; | ||
temp.style.color = state.tempColor; | ||
} else if (state.temp < 50) { | ||
state.tempColor = 'teal'; | ||
temp.style.color = state.tempColor; | ||
} | ||
}; | ||
|
||
const changeBackImg = () => { | ||
if (state.temp >= 80) { | ||
state.tempBackground = 'url(../src/images/sunny.png)'; | ||
backColor.style.backgroundImage = state.tempBackground; | ||
backColor.style.color = 'black'; | ||
} else if (state.temp < 80 && state.temp > 69) { | ||
state.tempBackground = 'url(../src/images/spring.png)'; | ||
backColor.style.backgroundImage = state.tempBackground; | ||
backColor.style.color = 'white'; | ||
} else if (state.temp < 70 && state.temp > 59) { | ||
state.tempBackground = 'url(../src/images/cool.png)'; | ||
backColor.style.backgroundImage = state.tempBackground; | ||
backColor.style.color = 'white'; | ||
} else if (state.temp < 60) { | ||
state.tempBackground = 'url(../src/images/snow.png)'; | ||
backColor.style.color = 'white'; | ||
backColor.style.backgroundImage = state.tempBackground; | ||
} | ||
}; | ||
|
||
const increaseTemp = () => { | ||
state.temp++; | ||
temp.textContent = `${state.temp}°`; | ||
changetempColor(); | ||
changeBackImg(); | ||
}; | ||
|
||
const decreaseTemp = () => { | ||
state.temp--; | ||
temp.textContent = `${state.temp}°`; | ||
changetempColor(); | ||
changeBackImg(); | ||
}; | ||
|
||
const registerEventHandlers = () => { | ||
const upArrow = document.getElementById('arrow-up'); | ||
upArrow.addEventListener('click', increaseTemp); | ||
|
||
const downArrow = document.getElementById('arrow-down'); | ||
downArrow.addEventListener('click', decreaseTemp); | ||
}; | ||
|
||
document.addEventListener('DOMContentLoaded', registerEventHandlers); |
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