Weather Checker

Weather Checker

weather-container { max-width: 400px; margin: 40px auto; padding: 20px; background-color: #f7f7f7; border: 1px solid #ddd; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } #city { width: 100%; padding: 10px; margin-bottom: 20px; } #check-weather { background-color: #4CAF50; color: #fff; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; } #weather-data { margin-top: 20px; } const cityInput = document.getElementById('city'); const checkWeatherButton = document.getElementById('check-weather'); const weatherDataDiv = document.getElementById('weather-data'); checkWeatherButton.addEventListener('click', () => { const city = cityInput.value; fetch(`https://api.openweathermap.org/data/2.5/weather?q=${city}&units=metric&appid=YOUR_API_KEY`) .then(response => response.json()) .then(data => { const weatherData = `

Weather in ${city}

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

Humidity: ${data.main.humidity}%

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

`; weatherDataDiv.innerHTML = weatherData; }) .catch(error => console.error(error)); });