-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
27 lines (18 loc) · 1.14 KB
/
main.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
const searchBox = document.querySelector(".search");
const searchBtn = document.querySelector(".search-btn");
async function checkWeather(city) {
const apikey = "ca58c19f5ef14f1cb4591244241406";
const apiurl = `https://api.weatherapi.com/v1/current.json?key=${apikey}&q=${city}&aqi=yes`;
const weatherData = await fetch(`${apiurl}`).then(response => response.json());
document.getElementById("place").innerHTML = weatherData.location.name;
document.getElementById("temperature").innerHTML = Math.round(weatherData.current.temp_c) + "°c" ;
document.querySelector(".aqi").innerHTML = "AQI " + weatherData.current.air_quality.co;
document.querySelector(".heatidx").innerHTML = "Feels Like " + weatherData.current.heatindex_c;
document.querySelector("#humidity").innerHTML = weatherData.current.humidity+ " %";
document.querySelector("#speed").innerHTML = weatherData.current.wind_kph + " km/h";
document.querySelector(".weather-icon").src = weatherData.current.condition.icon;
document.querySelector(".weather-info").classList.remove("none");
}
searchBtn.addEventListener("click",()=>{
checkWeather(searchBox.value);
});