-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
49 lines (35 loc) · 1.23 KB
/
script.js
File metadata and controls
49 lines (35 loc) · 1.23 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
42
43
44
45
46
47
48
49
const url = 'https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city=Delhi';
const options = {
method: 'GET',
headers: {
'X-RapidAPI-Key': '72194ba2b6msh49a2ec6d5156701p184235jsnecfc9d4544a6',
'X-RapidAPI-Host': 'weather-by-api-ninjas.p.rapidapi.com'
}
};
const getWheather = (city) => {
fetch('https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city='+city, options)
.then(response => response.json())
.then((response)=>{
console.log(response)
var rise = new Date(response.sunrise);
var set = new Date(response.sunset);
var Rise = rise.getHours()+
":"+rise.getMinutes()+
":"+rise.getSeconds();
var Set = set.getHours()+
":"+set.getMinutes()+
":"+set.getSeconds();
cloud_pct.innerHTML = response.cloud_pct
temp.innerHTML = response.temp
feels_like.innerHTML = response.feels_like
humidity.innerHTML = response.humidity
min_temp.innerHTML = response.min_temp
max_temp.innerHTML = response.max_temp
wind_speed.innerHTML = response.wind_speed
wind_degrees.innerHTML = response.wind_degrees
sunrise.innerHTML = Rise
sunset.innerHTML = Set
})
.catch(err => console.error(err));
}
getWheather("Delhi");