diff --git a/weatherforecast.js b/weatherforecast.js new file mode 100644 index 0000000..7443c18 --- /dev/null +++ b/weatherforecast.js @@ -0,0 +1,46 @@ +// Sample data for daily weather and 5-day forecast +const dailyWeather = { + temperature: "75°F", + condition: "Sunny", +}; + +const fiveDayForecast = [ + { day: "Monday", temperature: "70°F", condition: "Cloudy" }, + { day: "Tuesday", temperature: "72°F", condition: "Rainy" }, + { day: "Wednesday", temperature: "68°F", condition: "Sunny" }, + { day: "Thursday", temperature: "74°F", condition: "Partly Cloudy" }, + { day: "Friday", temperature: "78°F", condition: "Sunny" }, +]; + +// Function to render daily weather +function renderDailyWeather() { + const dailyWeatherCard = document.getElementById("daily-weather"); + dailyWeatherCard.innerHTML = ` +
Temperature: ${dailyWeather.temperature}
+ `; +} + +// Function to render 5-day forecast +function renderFiveDayForecast() { + const fiveDayForecastContainer = document.getElementById("five-day-forecast"); + fiveDayForecast.forEach((day) => { + const forecastCard = document.createElement("div"); + forecastCard.classList.add("weather-card"); + forecastCard.innerHTML = ` +Temperature: ${day.temperature}
+Condition: ${day.condition}
+ `; + fiveDayForecastContainer.appendChild(forecastCard); + }); +} + +// Initialize the weather data +function init() { + renderDailyWeather(); + renderFiveDayForecast(); +} + +// Call the init function to load data +init();