| 49 | } |
| 50 | |
| 51 | function weatherDetails(info){ |
| 52 | if(info.cod == "404"){ |
| 53 | infoTxt.classList.replace("pending", "error"); |
| 54 | infoTxt.innerText = `${inputField.value} isn't a valid city name`; |
| 55 | }else{ |
| 56 | const city = info.name; |
| 57 | const country = info.sys.country; |
| 58 | const {description, id} = info.weather[0]; |
| 59 | const {temp, feels_like, humidity} = info.main; |
| 60 | |
| 61 | if(id == 800){ |
| 62 | wIcon.src = "icons/clear.svg"; |
| 63 | }else if(id >= 200 && id <= 232){ |
| 64 | wIcon.src = "icons/storm.svg"; |
| 65 | }else if(id >= 600 && id <= 622){ |
| 66 | wIcon.src = "icons/snow.svg"; |
| 67 | }else if(id >= 701 && id <= 781){ |
| 68 | wIcon.src = "icons/haze.svg"; |
| 69 | }else if(id >= 801 && id <= 804){ |
| 70 | wIcon.src = "icons/cloud.svg"; |
| 71 | }else if((id >= 500 && id <= 531) || (id >= 300 && id <= 321)){ |
| 72 | wIcon.src = "icons/rain.svg"; |
| 73 | } |
| 74 | |
| 75 | weatherPart.querySelector(".temp .numb").innerText = Math.floor(temp); |
| 76 | weatherPart.querySelector(".weather").innerText = description; |
| 77 | weatherPart.querySelector(".location span").innerText = `${city}, ${country}`; |
| 78 | weatherPart.querySelector(".temp .numb-2").innerText = Math.floor(feels_like); |
| 79 | weatherPart.querySelector(".humidity span").innerText = `${humidity}%`; |
| 80 | infoTxt.classList.remove("pending", "error"); |
| 81 | infoTxt.innerText = ""; |
| 82 | inputField.value = ""; |
| 83 | wrapper.classList.add("active"); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | arrowBack.addEventListener("click", ()=>{ |
| 88 | wrapper.classList.remove("active"); |