Selmy44 / Weather-App1

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

<title>Weather App</title>

Weather App

Get Weather
<script> async function getWeather() { const city = document.getElementById('city').value; const apiKey = 'YOUR_API_KEY'; // Replace with your API key from a weather service provider const apiUrl = `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}&units=metric`; try { const response = await fetch(apiUrl); const data = await response.json(); const weatherInfo = document.getElementById('weather-info'); weatherInfo.innerHTML = `

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

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

Weather: ${data.weather[0].description}

`; } catch (error) { console.error('Error fetching data:', error); const weatherInfo = document.getElementById('weather-info'); weatherInfo.innerHTML = 'Error fetching weather data'; } } </script>

About


Languages

Language:HTML 100.0%