-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
59 lines (54 loc) · 1.73 KB
/
script.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const options = {
method: "GET",
headers: {
"x-rapidapi-key": "0b5cb101a2msh4f819749598bdefp1ce794jsn12d1542afa53",
"x-rapidapi-host": "weatherapi-com.p.rapidapi.com",
},
};
const getWeather = (city) => {
fetch(
"https://weatherapi-com.p.rapidapi.com/current.json?q=" + city,
options
)
.then((response) => response.json())
.then((response) => {
console.log(response);
cityName.innerHTML = city;
const res = response.current;
temp.innerHTML = res.temp_c;
temp2.innerHTML = res.temp_c;
feels_like.innerHTML = res.feelslike_c;
humidity.innerHTML = res.humidity;
humidity2.innerHTML = res.humidity;
pressure.innerHTML = res.pressure_mb;
gust.innerHTML = res.gust_kph;
wind_speed.innerHTML = res.wind_kph;
wind_degrees.innerHTML = res.wind_degree;
wind_degrees2.innerHTML = res.wind_degree;
timeZone.innerHTML = response.location.tz_id;
lastUpdate.innerHTML = res.last_updated;
year.innerHTML = response.location.localtime.slice(0, 4);
})
.catch((err) => {
console.error(err),
head.innerHTML = "Please check the spelling of the location you entered.";
cityName.innerHTML = "";
});
};
submit.addEventListener("click", (e) => {
e.preventDefault();
getWeather(city.value);
});
getWeather("Patna");
document.querySelector("#Delhi").addEventListener("click", (e) => {
e.preventDefault();
getWeather("Delhi");
});
document.querySelector("#Patna").addEventListener("click", (e) => {
e.preventDefault();
getWeather("Patna");
});
document.querySelector("#Kolkata").addEventListener("click", (e) => {
e.preventDefault();
getWeather("Kolkata");
});