Skip to content
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

complete wave 03 #3

Merged
merged 1 commit into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h1 class="logo">Weather App</h1>
<h1 class="h1-temp">Temperature in</h1>

<div class="temp-box-header">
<p id="city-state">Dallas, TX</p>
<p id="city-state">Dallas</p>
<button>Get Current Temp</button>
</div>

Expand Down
24 changes: 24 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ const state = {
temp: 80,
tempColor: 'red',
tempBackground: 'url(../src/images/sunny.png)',
cityName: 'Dallas',
};

// Default Values
const temp = document.getElementById('temp');
temp.textContent = state.temp + '°';
temp.style.color = state.tempColor;
temp.style.color = state.cityName;

const backColor = document.getElementsByTagName('main')[0];
backColor.style.backgroundImage = state.tempBackground;

// Change the color of the temp
const changetempColor = () => {
if (state.temp >= 80) {
state.tempColor = 'red';
Expand All @@ -32,6 +36,7 @@ const changetempColor = () => {
}
};

// Change the background image by temp
const changeBackImg = () => {
if (state.temp >= 80) {
state.tempBackground = 'url(../src/images/sunny.png)';
Expand All @@ -52,6 +57,7 @@ const changeBackImg = () => {
}
};

// Increase & Decrease the temp
const increaseTemp = () => {
state.temp++;
temp.textContent = `${state.temp}°`;
Expand All @@ -66,12 +72,30 @@ const decreaseTemp = () => {
changeBackImg();
};

// Change city name by input box
const changeCity = (e) => {
const searchCity = document.getElementById('search-box');
const cityState = document.getElementById('city-state');
state.cityName = e.target.value;
cityState.textContent = state.cityName;
};

// Reset city name by button
const resetCity = () => {};

// Event Handlers
const registerEventHandlers = () => {
const upArrow = document.getElementById('arrow-up');
upArrow.addEventListener('click', increaseTemp);

const downArrow = document.getElementById('arrow-down');
downArrow.addEventListener('click', decreaseTemp);

const searchCity = document.getElementById('search-box');
searchCity.addEventListener('input', changeCity);

const searchResetBtn = document.getElementById('search-reset-btn');
searchResetBtn.addEventListener('click', resetCity);
};

document.addEventListener('DOMContentLoaded', registerEventHandlers);