-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
22 lines (20 loc) · 949 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const button = document.getElementById("search-button");
const input= document.getElementById("city-input");
async function getData(cityName){
const promise = await fetch(`http://api.weatherapi.com/v1/current.json?key=a507436a08a14933a0e141612241303&q=${cityName}&aqi=yes`);
return await promise.json()
}
const cityName= document.getElementById("cityName");
const cityTime = document.getElementById("cityTime");
const cityTemp= document.getElementById("cityTemp");
button.addEventListener('click', async() =>{
//console.log(input.value);
const value = input.value;
const result = await getData(value);
console.log(result);
cityName.innerText=`${result.location.name},
${result.location.region} - ${result.location.country}`;
cityTime.innerText = result.location.localtime;
cityTemp.innerText = result.current.temp_c;
});
//http://api.weatherapi.com/v1/current.json?key=a507436a08a14933a0e141612241303&q=London&aqi=yes