-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (28 loc) · 879 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
23
24
25
26
27
28
29
30
document.getElementById("search").addEventListener("click", apicall);
function apicall() {
const apikey = config.apikey;
const cityname = document.getElementById("cityname").value;
const url = `https://api.weatherapi.com/v1/current.json?key=${apikey}&q=${cityname}&days=3&aqi=yes&alerts=no`;
fetch(url)
.then((response) => response.json())
.then((data) => {
let currtemp = `
<div>
<p>${data.current.temp_c}<sup>℃</p>
</div>`
;
document.getElementById("currtemp").innerHTML = currtemp;
let condition = `
<div>
<p>${data.current.condition.text}</p>
</div>`
;
document.getElementById("condition").innerHTML = condition;
let windspeed = `
<div>
<p>${data.current.wind_kph}<sup>kmph</p>
</div>`
;
document.getElementById("windspeed").innerHTML = windspeed;
}).catch((err) => console.log(err));
}