WP Assignment
WP Assignment
WP Assignment
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<div class="dashboard-container">
<h1>Weather Dashboard</h1>
<div class="search-container">
</div>
<div class="weather-display">
<div class="current-weather">
<div class="weather-icon">
</div>
<h2 id="cityName">City</h2>
</div>
<div class="forecast-container">
<h2>5-Day Forecast</h2>
<div id="forecast" class="forecast-grid"></div>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
CSS CODE
*{
margin: 0;
padding: 0;
box-sizing: border-box;
body {
background-color: #f0f0f0;
.dashboard-container {
max-width: 900px;
margin: 0 auto;
padding: 20px;
text-align: center;
.search-container {
}
input {
padding: 10px;
width: 60%;
border-radius: 8px;
bu on {
padding: 10px;
background-color: #007bff;
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
bu on:hover {
background-color: #0056b3;
.weather-display {
display: flex;
align-items: center;
.current-weather {
background-color: #fff;
padding: 20px;
border-radius: 12px;
width: 100%;
max-width: 600px;
.weather-icon img {
width: 100px;
height: 100px;
#cityName {
font-size: 28px;
margin-top: 10px;
font-size: 18px;
margin-top: 5px;
.forecast-container {
max-width: 600px;
width: 100%;
.forecast-grid {
display: grid;
gap: 10px;
.forecast-item {
background-color: #f9f9f9;
padding: 10px;
border-radius: 8px;
text-align: center;
.forecast-item img {
width: 50px;
height: 50px;
.sunny {
background-color: gold;
.rainy {
background-color: #5f9ea0;
.cloudy {
background-color: #d3d3d3;
.windy {
background-color: #1b1b1b;
.stormy {
background-color: #2c3e50;
if (city) {
fetchWeatherData(city);
});
func on fetchWeatherData(city) {
const apiUrl =
`h ps://api.openweathermap.org/data/2.5/weather?q=${city}&units=metric&appid=${apiKey}`;
fetch(apiUrl)
.then(data => {
displayCurrentWeather(data);
fetchForecast(city);
})
.catch(error => {
});
func on fetchForecast(city) {
const apiUrl =
`h ps://api.openweathermap.org/data/2.5/forecast?q=${city}&units=metric&appid=${apiKey}`;
fetch(apiUrl)
displayForecast(data.list);
});
func on displayCurrentWeather(data) {
document.getElementById('cityName').innerText = data.name;
document.getElementById('weatherIcon').src =
`h p://openweathermap.org/img/wn/${data.weather[0].icon}@2x.png`;
applyWeatherStyle(data.weather[0].main.toLowerCase());
func on displayForecast(forecastData) {
forecastContainer.innerHTML = '';
filteredForecast.forEach(day => {
forecastItem.classList.add('forecast-item');
forecastItem.innerHTML = `
<h3>${new Date(day.dt_txt).toLocaleDateString()}</h3>
<p>${day.main.temp}°C</p>
<p>${day.weather[0].main}</p>
`;
forecastContainer.appendChild(forecastItem);
});
}
case 'clear':
case 'sunny':
document.body.classList.add('sunny');
break;
case 'rain':
case 'drizzle':
document.body.classList.add('rainy');
break;
case 'clouds':
document.body.classList.add('cloudy');
break;
case 'wind':
document.body.classList.add('windy');
break;
case 'storm':
case 'thunderstorm':
document.body.classList.add('stormy');
break;
default:
document.body.classList.add('cloudy');
break;
}
OUTPUT