Weaither
Weaither
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>
.container {
text-align: center;
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 0 15px rgba(0,0,0,0.2);
}
input {
padding: 10px;
width: 200px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 5px;
}
button {
padding: 10px 20px;
background-color: #3498db;
border: none;
color: white;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #2980b9;
}
#weatherResult {
margin-top: 20px;
font-size: 18px;
}
</style>
</head>
<body>
<div class="container">
<h1>Weather App</h1>
<input type="text" id="locationInput" placeholder="Enter location..." />
<button onclick="getWeather()">Get Weather</button>
<div id="weatherResult"></div>
</div>
fetch(url)
.then(response => {
if (!response.ok) {
throw new Error('Location not found');
}
return response.json();
})
.then(data => {
const tempC = data.current.temp_c;
const condition = data.current.condition.text;
const weatherResult = document.getElementById('weatherResult');
weatherResult.innerHTML = `
<strong>${data.location.name}, ${data.location.country}</strong><br/>
Temperature: ${tempC}°C<br/>
Condition: ${condition}
`;
})
.catch(error => {
document.getElementById('weatherResult').innerHTML = `Error: $
{error.message}`;
});
}
</script>
</body>
</html>