-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
41 lines (36 loc) · 1.12 KB
/
script.js
File metadata and controls
41 lines (36 loc) · 1.12 KB
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
let city = "Delhi";
const weather = async (ccc) => {
const url =
"https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city=" + ccc;
const options = {
method: "GET",
headers: {
"X-RapidAPI-Key": "02b32bbd9emsh359897c9d689fe4p18528ajsn4346db6bd2ee",
"X-RapidAPI-Host": "weather-by-api-ninjas.p.rapidapi.com",
},
};
try {
const response = await fetch(url, options);
const result = await response.json();
cityname.innerHTML = city;
temp.innerHTML = result.temp + "°";
humi.innerHTML = result.humidity;
cloud_pct.innerHTML = result.cloud_pct;
feels_like.innerHTML = result.feels_like;
min_temp.innerHTML = result.min_temp;
// sunrise.innerHTML = result.sunrise;
// sunset.innerHTML = result.sunset;
wind_degrees.innerHTML = result.wind_degrees;
wind_speed.innerHTML = result.wind_speed;
max_temp.innerHTML = result.max_temp;
console.log(result);
} catch (error) {
console.error(error);
}
};
// weather(city);
btn.addEventListener("click", () => {
const val = document.getElementsByTagName("input")[0].value;
weather(val);
city=val;
});