From cebb4971beb48a2e6d19ac69623466ea29affc15 Mon Sep 17 00:00:00 2001 From: mohammed kaif Date: Sun, 12 May 2024 23:30:52 +0500 Subject: [PATCH] 85% WORK DONE --- script.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/script.js b/script.js index 5076245..0d8eead 100644 --- a/script.js +++ b/script.js @@ -14,13 +14,20 @@ form.addEventListener("submit", (event) => { } }); -let id = "9505fd1df737e20152fbd78cdb289b6a" -let url = "https://api.openweathermap.org/data/2.5/weather?units=metric&appid" + id +let id = "9505fd1df737e20152fbd78cdb289b6a"; +let url = + "https://api.openweathermap.org/data/2.5/weather?units=metric&appid=" + id; -const searchWeather = () =>{ - fetch(url ) - .then(responsive => responsive.json()) - .then(data =>{ - console.log((data)); - }) -} \ No newline at end of file +const searchWeather = () => { + fetch(url + "&q=" + getInput.value) + .then((responsive) => responsive.json()) + .then((data) => { + console.log(data); + if (data.cod == 200) { + city.querySelector("figcaption").innerHTML = data.name; + city.querySelector("img").src = 'https://flagsapi.com/'+data.sys.country+'/shiny/32.png' + + temperature.querySelector("img").src = 'http:openweathermap.org/img/wn/'+data.weather[0].icon+'@4x.png' + } + }); +};