-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
144 lines (115 loc) · 5.02 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
const options = {
method: 'GET',
headers: {
'X-RapidAPI-Key': 'e73e03a2b6msh6919b8eb9a91cf9p16d9eejsn0818b225fc92',
'X-RapidAPI-Host': 'weather-by-api-ninjas.p.rapidapi.com'
}
};
getdata=(city)=>{
cityName.innerHTML=city
fetch('https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city='+city, options)
.then(response => response.json())
.then(response => {
temp.innerHTML= response.temp,
wind_speed.innerHTML= response.wind_speed,
// "feels_like": 15,
humidity.innerHTML= response.humidity,
// "min_temp": 16,
// "max_temp": 16,
// "wind_degrees": 270,
// "sunrise": 1671673206,
// "sunset": 1671710333,
// cloud_pct.innerHTML= response.cloud_pct,
console.log(response)
if(temp.innerHTML===null) {
console.log("enter the valid city");
} else {
}
})
.catch(err => console.log(err+"an error has ocuured"));
}
fetch('https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city=delhi', options)
.then(response => response.json())
.then(response => {
delhi_temp.innerHTML= response.temp,
delhi_wind_speed.innerHTML= response.wind_speed,
// "feels_like": 15,
delhi_humidity.innerHTML= response.humidity,
// "min_temp": 16,
// "max_temp": 16,
// "wind_degrees": 270,
// "sunrise": 1671673206,
// "sunset": 1671710333,
// cloud_pct.innerHTML= response.cloud_pct,
console.log(response)
if(temp.innerHTML===null) {
console.log("enter the valid city");
} else {
}
})
.catch(err => console.log(err+"an error has ocuured"));
fetch('https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city=london', options)
.then(response => response.json())
.then(response => {
london_temp.innerHTML= response.temp,
london_wind_speed.innerHTML= response.wind_speed,
// "feels_like": 15,
london_humidity.innerHTML= response.humidity,
// "min_temp": 16,
// "max_temp": 16,
// "wind_degrees": 270,
// "sunrise": 1671673206,
// "sunset": 1671710333,
// cloud_pct.innerHTML= response.cloud_pct,
console.log(response)
if(temp.innerHTML===null) {
console.log("enter the valid city");
} else {
}
})
.catch(err => console.log(err+"an error has ocuured"));
fetch('https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city=new york', options)
.then(response => response.json())
.then(response => {
newyork_temp.innerHTML= response.temp,
newyork_wind_speed.innerHTML= response.wind_speed,
// "feels_like": 15,
newyork_humidity.innerHTML= response.humidity,
// "min_temp": 16,
// "max_temp": 16,
// "wind_degrees": 270,
// "sunrise": 1671673206,
// "sunset": 1671710333,
// cloud_pct.innerHTML= response.cloud_pct,
console.log(response)
if(temp.innerHTML===null) {
console.log("enter the valid city");
} else {
}
})
.catch(err => console.log(err+"an error has ocuured"));
fetch('https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city=tokyo', options)
.then(response => response.json())
.then(response => {
tokyo_temp.innerHTML= response.temp,
tokyo_wind_speed.innerHTML= response.wind_speed,
// "feels_like": 15,
tokyo_humidity.innerHTML= response.humidity,
// "min_temp": 16,
// "max_temp": 16,
// "wind_degrees": 270,
// "sunrise": 1671673206,
// "sunset": 1671710333,
// cloud_pct.innerHTML= response.cloud_pct,
console.log(response)
if(temp.innerHTML===null) {
console.log("enter the valid city");
} else {
}
})
.catch(err => console.log(err+"an error has ocuured"));
document.getElementById("submit").addEventListener("click",(e)=>{
e.preventDefault();
getdata(document.getElementById("city").value)
})
getdata("delhi")