Skip to content

issue #4

@faisalshaik78

Description

@faisalshaik78

const apiKey = 'YOUR_API_KEY_HERE'; // Replace with your OpenWeatherMap API key
const searchBtn = document.getElementById('search-btn');
const cityInput = document.getElementById('city-input');
const weatherInfo = document.getElementById('weather-info');

searchBtn.addEventListener('click', () => {
const city = cityInput.value;
if (city) {
fetch(https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}&units=metric)
.then(response => response.json())
.then(data => {
if (data.cod === 200) {
weatherInfo.innerHTML = <h2>${data.name}, ${data.sys.country}</h2> <p>Temperature: ${data.main.temp}°C</p> <p>Weather: ${data.weather[0].description}</p> <p>Humidity: ${data.main.humidity}%</p>;
} else {
weatherInfo.innerHTML = '

City not found. Try again.

';
}
})
.catch(error => console.error('Error:', error));
}
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions