-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53a249d
commit eb043a6
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Weather App</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<div class="weather-app"> | ||
<h1>Weather App</h1> | ||
<input type="text" id="cityInput" placeholder="Enter city name"> | ||
<button id="getWeather">Get Weather</button> | ||
<div id="weatherResult" class="weather-result"></div> | ||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const apiKey = "eb9671fdb92c77708e5fed1178ded9b3"; // Replace with your OpenWeatherMap API key | ||
const getWeatherButton = document.getElementById("getWeather"); | ||
const weatherResult = document.getElementById("weatherResult"); | ||
|
||
getWeatherButton.addEventListener("click", async () => { | ||
const city = document.getElementById("cityInput").value; | ||
|
||
if (!city) { | ||
weatherResult.innerHTML = "Please enter a city name."; | ||
return; | ||
} | ||
|
||
try { | ||
const response = await fetch( | ||
`https://api.openweathermap.org/data/2.5/weather?q=${city}&units=metric&appid=${apiKey}` | ||
); | ||
|
||
if (!response.ok) { | ||
weatherResult.innerHTML = `Error: ${response.statusText}`; | ||
return; | ||
} | ||
|
||
const weatherData = await response.json(); | ||
|
||
const { name, main, weather, wind } = weatherData; | ||
const temperature = main.temp; | ||
const description = weather[0].description; | ||
const humidity = main.humidity; | ||
const windSpeed = wind.speed; | ||
|
||
weatherResult.innerHTML = ` | ||
<h2>Weather in ${name}</h2> | ||
<p><strong>Temperature:</strong> ${temperature}°C</p> | ||
<p><strong>Description:</strong> ${description}</p> | ||
<p><strong>Humidity:</strong> ${humidity}%</p> | ||
<p><strong>Wind Speed:</strong> ${windSpeed} m/s</p> | ||
`; | ||
} catch (error) { | ||
weatherResult.innerHTML = `Error: ${error.message}`; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
background: linear-gradient(to bottom, #6dd5fa, #2980b9); | ||
color: #fff; | ||
text-align: center; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
.weather-app { | ||
padding: 20px; | ||
margin-top: 50px; | ||
} | ||
|
||
input, button { | ||
padding: 10px; | ||
font-size: 16px; | ||
margin: 10px 5px; | ||
border-radius: 5px; | ||
border: none; | ||
} | ||
|
||
input { | ||
width: 200px; | ||
} | ||
|
||
button { | ||
background-color: #2980b9; | ||
color: #fff; | ||
cursor: pointer; | ||
} | ||
|
||
button:hover { | ||
background-color: #21618c; | ||
} | ||
|
||
.weather-result { | ||
margin-top: 20px; | ||
padding: 20px; | ||
background: rgba(255, 255, 255, 0.1); | ||
border-radius: 10px; | ||
} | ||
|