☀️ Weather

Real-time weather forecasts powered by wttr.in

Loading...
Loading...
'; try { const response = await fetch(`https://wttr.in/${encodeURIComponent(city)}?format=j1`); const data = await response.json(); const current = data.current_condition[0]; const location = data.nearest_area[0]; const forecast = data.weather; display.innerHTML = `
${current.temp_C}°C
${current.weatherDesc[0].value}
${location.areaName[0].value}, ${location.country[0].value}
Feels Like
${current.FeelsLikeC}°C
Humidity
${current.humidity}%
Wind
${current.windspeedKmph} km/h
3-Day Forecast
${forecast.slice(0, 3).map((day, i) => { const date = new Date(); date.setDate(date.getDate() + i); const dayName = i === 0 ? 'Today' : date.toLocaleDateString('en-US', { weekday: 'long' }); return `
${dayName} ${day.hourly[4].weatherDesc[0].value} ${day.mintempC}° / ${day.maxtempC}°C
`; }).join('')}
`; } catch (error) { display.innerHTML = '
Failed to load weather. Try again.
'; } } getWeather(); document.getElementById('cityInput').addEventListener('keypress', function(e) { if (e.key === 'Enter') getWeather(); });