-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
29 lines (24 loc) · 810 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
const cityInput = document.getElementById("input");
const dispalySection = document.getElementById("display");
const API_KEY = "650ad8fb3c6e4ecab3190253232706";
const handleClick = () => {
let currentCity = cityInput.value;
const getWeather = fetch(
`https://api.weatherapi.com/v1/current.json?key=${API_KEY}&q=${
currentCity || "London"
}&aqi=no`
)
.then((res) => res.json())
.then((data) => {
dispalySection.innerHTML =
` <p>${data.location.name}'s temperature is ${data.current.temp_c}℃.</p>
<p>It's ${data.current.condition.text}.</p>
<img src="${data.current.condition.icon}" alt="icon"/>
`;
})
.catch((err) => {
console.log(err);
dispalySection.innerText = `Please enter a vaild city.`;
});
};
handleClick();