Skip to content

Commit

Permalink
Completed wave 5 - updateSky
Browse files Browse the repository at this point in the history
  • Loading branch information
tramhn001 committed Dec 5, 2024
1 parent 469ecc5 commit 7d32299
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ <h2>Temperature</h2>
<section class="sky__section">
<h2>Sky</h2>
<select id="skySelect">
<!-- sky options here -->
<option value="Sunny">Sunny</option>
<option value="Cloudy">Cloudy</option>
<option value="Rainy">Rainy</option>
<option value="Snowy">Snowy</option>
</select>
</section>

Expand Down
46 changes: 44 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ const updateTemperature = () => {
landScrape.textContent = "🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷";
} else if (currentTemperature >= 60) {
tempValue.style.color = 'yellow';
tempValue.style.backgroundColor = '#FFE4B5';
tempValue.style.backgroundColor = 'pink';
landScrape.textContent = "🌾🌾_🍃_🪨__🛤_🌾🌾🌾_🍃";
} else if (currentTemperature >= 50) {
tempValue.style.color = 'green';
tempValue.style.backgroundColor = '#CCFFCC';
landScrape.textContent = "🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲";
landScrape.textContent = "🌲🌲🍂🌲🍁🍃🌲🌾🌲🌲🍂🍁🌲";
} else if (currentTemperature >= 40) {
tempValue.style.color = 'teal';
tempValue.style.backgroundColor = '#CCFFFF';
Expand Down Expand Up @@ -73,6 +73,21 @@ document.addEventListener("DOMContentLoaded", () => {
currentTemperature = Math.round(tempFahrenheit);
updateTemperature();

// Update the sky based on weather condition
const weatherCondition = weatherResponse.data.weather.main;
let skyType = "Sunny"; // Default sky

if (weatherCondition.includes("Rain")) {
skyType = "Rainy";
} else if (weatherCondition.includes("Snow")) {
skyType = "Snowy";
} else if (weatherCondition.includes("Cloud")) {
skyType = "Cloudy";
}

skySelect.value = skyType; // Sync dropdown
updateSky(skyType);

} catch (error) {
console.error("Error fetching weather data:", error);
}
Expand All @@ -87,9 +102,36 @@ document.addEventListener("DOMContentLoaded", () => {
headerCityName.textContent = "Seattle";
currentTemperature = 70;
updateTemperature();
updateSky("Sunny");
skySelect.value = "Sunny";
});

updateTemperature();
});

// Wave 5
const updateSky = () => {
const skySelect = document.getElementById('skySelect');
const skyElement = document.getElementById('sky');

const skyOptions = {
Sunny: "☁️ ☁️ ☁️ ☀️ ☁️ ☁️",
Cloudy: "☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️",
Rainy: "🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧",
Snowy: "🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨",
};

const selectedSky = skySelect.value;
skyElement.textContent = skyOptions[selectedSky];
};

// Add an event listener to the select dropdown for changing the sky
document.getElementById('skySelect').addEventListener('change', updateSky);

document.addEventListener("DOMContentLoaded", () => {
updateSky("Sunny");
updateTemperature();
});



10 changes: 8 additions & 2 deletions styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ padding: 1rem;
font-family: "Rubik", sans-serif;
}

.red {
/* .red {
color: red;
}
Expand Down Expand Up @@ -161,4 +161,10 @@ background-color: lightblue;
.snowy {
background-color: lightsteelblue;
}
} */

#skyDisplay {
font-size: 2rem;
text-align: center;
margin-top: 10px;
}

0 comments on commit 7d32299

Please sign in to comment.