Very simple weather app

This commit is contained in:
2024-07-19 19:08:23 +02:00
parent da519290c2
commit 88c8a378c1
5 changed files with 392 additions and 1 deletions
+57
View File
@@ -0,0 +1,57 @@
<!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>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
}
.container {
background-color: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
input, button {
margin: 10px 0;
padding: 5px;
}
</style>
</head>
<body>
<div class="container">
<h1>Weather App</h1>
<input type="text" id="cityInput" placeholder="Enter city name">
<button onclick="getWeather()">Get Weather</button>
<div id="weatherInfo"></div>
</div>
<script>
function getWeather() {
const city = document.getElementById('cityInput').value;
fetch(`/weather?city=${encodeURIComponent(city)}`)
.then(response => response.json())
.then(data => {
const weatherInfo = document.getElementById('weatherInfo');
weatherInfo.innerHTML = `
<h2>Weather in ${city}</h2>
<p>Temperature: ${data.temperature}°C</p>
<p>Condition: ${data.condition}</p>
`;
})
.catch(error => {
console.error('Error:', error);
const weatherInfo = document.getElementById('weatherInfo');
weatherInfo.innerHTML = '<p>Error fetching weather data</p>';
});
}
</script>
</body>
</html>