Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
SpantaAlizadeh10 authored Dec 23, 2024
1 parent 53a249d commit eb043a6
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
18 changes: 18 additions & 0 deletions get weather/index.html
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>
41 changes: 41 additions & 0 deletions get weather/script.js
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}`;
}
});
43 changes: 43 additions & 0 deletions get weather/styles.css
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;
}

0 comments on commit eb043a6

Please sign in to comment.