From 0c9b51d7c00fe370978948d8ddc461523e1ed780 Mon Sep 17 00:00:00 2001 From: shruti-codes-design Date: Sun, 7 Jun 2026 23:15:06 +0530 Subject: [PATCH] Add Open Weather Forecast App --- public/OpenWeatherForecastApp/README.md | 0 public/OpenWeatherForecastApp/index.html | 24 +++++++++ public/OpenWeatherForecastApp/script.js | 54 +++++++++++++++++++ public/OpenWeatherForecastApp/style.css | 69 ++++++++++++++++++++++++ 4 files changed, 147 insertions(+) create mode 100644 public/OpenWeatherForecastApp/README.md create mode 100644 public/OpenWeatherForecastApp/index.html create mode 100644 public/OpenWeatherForecastApp/script.js create mode 100644 public/OpenWeatherForecastApp/style.css diff --git a/public/OpenWeatherForecastApp/README.md b/public/OpenWeatherForecastApp/README.md new file mode 100644 index 000000000..e69de29bb diff --git a/public/OpenWeatherForecastApp/index.html b/public/OpenWeatherForecastApp/index.html new file mode 100644 index 000000000..03a7281c6 --- /dev/null +++ b/public/OpenWeatherForecastApp/index.html @@ -0,0 +1,24 @@ + + + + + + Open Weather Forecast App + + + + +
+

🌤 Weather Forecast App

+ + + +
+
+ + + + \ No newline at end of file diff --git a/public/OpenWeatherForecastApp/script.js b/public/OpenWeatherForecastApp/script.js new file mode 100644 index 000000000..1cc8c8918 --- /dev/null +++ b/public/OpenWeatherForecastApp/script.js @@ -0,0 +1,54 @@ +const API_KEY = "YOUR_API_KEY"; +async function getWeather() { + const city = document.getElementById("cityInput").value.trim(); + const weatherData = document.getElementById("weatherData"); + + if (city === "") { + weatherData.innerHTML = "

Please enter a city name.

"; + return; + } + + weatherData.innerHTML = "

Loading...

"; + + const url = `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${API_KEY}&units=metric`; + + try { + const response = await fetch(url); + + if (!response.ok) { + throw new Error("City not found"); + } + + const data = await response.json(); + + weatherData.innerHTML = ` +

${data.name}, ${data.sys.country}

+ + Weather Icon + +

${data.weather[0].main}

+

${data.weather[0].description}

+ +

🌡 Temperature: ${data.main.temp} °C

+

🌡 Feels Like: ${data.main.feels_like} °C

+

💧 Humidity: ${data.main.humidity}%

+

🌬 Wind Speed: ${data.wind.speed} m/s

+`; + } catch (error) { + console.log(error); + weatherData.innerHTML = + `

${error.message}

`; + } + } + document + .getElementById("cityInput") + .addEventListener("keypress", function(event) { + if (event.key === "Enter") { + getWeather(); + } + }); + \ No newline at end of file diff --git a/public/OpenWeatherForecastApp/style.css b/public/OpenWeatherForecastApp/style.css new file mode 100644 index 000000000..e977762a1 --- /dev/null +++ b/public/OpenWeatherForecastApp/style.css @@ -0,0 +1,69 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; + font-family: Arial, sans-serif; +} + +body { + min-height: 100vh; + background: linear-gradient(135deg, #4facfe, #00f2fe); + display: flex; + justify-content: center; + align-items: center; +} + +.container { + width: 90%; + max-width: 450px; + background: white; + padding: 25px; + border-radius: 15px; + text-align: center; + box-shadow: 0 5px 20px rgba(0,0,0,0.2); +} + +h1 { + margin-bottom: 20px; + color: #333; +} + +.search-box { + display: flex; + gap: 10px; + margin-bottom: 20px; +} + +.search-box input { + flex: 1; + padding: 10px; + border: 2px solid #ddd; + border-radius: 8px; + outline: none; +} + +.search-box button { + padding: 10px 15px; + border: none; + background: #0077ff; + color: white; + border-radius: 8px; + cursor: pointer; +} + +.search-box button:hover { + background: #005edb; +} + +#weatherData { + margin-top: 20px; +} + +.weather-icon { + width: 100px; + height: 100px; +} +.error { + color: red; + font-weight: bold; +} \ No newline at end of file