I'm trying to show the current weather conditions for the state I enter, but every time I do, it gives an error saying "wrong city name" and then shows as undefined.
const button = document.querySelector('.button');
const inputValue = document.querySelector('.inputValue');
const nam = document.querySelector('.nam');
const desc = document.querySelector('.desc');
const temp = document.querySelector('.temp');
button.addEventListener('click', function() {
fetch('https://api.openweathermap.org/data/2.5/weather?q=' + inputValue.value + '&appid=0c712e338cabb3996a78ae788fa566a1')
.then(response => response.json())
.then(data => {
const nameValue = data['nam'];
const temperature = data['main']['temp'];
const descValue = data['weather'][0]['description'];
nam.innerHTML = nameValue;
temp.innerHTML = temperature;
desc.innerHTML = descValue;
})
.catch(err => alert("Oops! Wrong City name!"));
});