-
Notifications
You must be signed in to change notification settings - Fork 0
/
scriptweather.js
153 lines (124 loc) · 3.78 KB
/
scriptweather.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
145
146
147
148
149
150
151
152
153
const options = {
method: 'GET',
headers: {
'X-RapidAPI-Key': '3adb6d35e0msh91536d2f83e7196p183949jsn88448c754e94',
'X-RapidAPI-Host': 'weather-by-api-ninjas.p.rapidapi.com'
}
};
const Weather = (city) => {
cname1 = city
;
cname.innerHTML = cname1.toUpperCase();
url = "https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city="+city
fetch(url, options)
.then(response => response.json())
.then(response => {
cloud_pct.innerHTML = response.cloud_pct
temp.innerHTML = response.temp
t1.innerHTML = response.temp
feels_like.innerHTML = response.feels_like
humidity.innerHTML = response.humidity
h.innerHTML = response.humidity
mintemp.innerHTML = response.min_temp
maxtemp.innerHTML = response.max_temp
wind_speed.innerHTML = response.wind_speed
winds.innerHTML = response.wind_speed
wind_degrees.innerHTML = response.wind_degrees
if (response.wind_speed<=50){
wind_type.innerHTML = "Breeze"
}
else if (response.wind_speed<=100){
wind_type.innerHTML = "Gale"
}
else if (response.wind_speed>100){
wind_type.innerHTML = "Storm"
}
console.log(response)
})
.catch(err => console.error(err));
}
const Weatherm = (city) => {
url = "https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city="+city
fetch(url, options)
.then(response => response.json())
.then(response => {
mc.innerHTML = response.cloud_pct
mt.innerHTML = response.temp
mf.innerHTML = response.feels_like
mh.innerHTML = response.humidity
mmn.innerHTML = response.min_temp
mmx.innerHTML = response.max_temp
mws.innerHTML = response.wind_speed
mwd.innerHTML = response.wind_degrees
})
.catch(err => console.error(err));
}
const Weatherr = (city) => {
url = "https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city="+city
fetch(url, options)
.then(response => response.json())
.then(response => {
rc.innerHTML = response.cloud_pct
rt.innerHTML = response.temp
rf.innerHTML = response.feels_like
rh.innerHTML = response.humidity
rmn.innerHTML = response.min_temp
rmx.innerHTML = response.max_temp
rws.innerHTML = response.wind_speed
rwd.innerHTML = response.wind_degrees
})
.catch(err => console.error(err));
}
const WeatherRj = (city) => {
url = "https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city="+city
fetch(url, options)
.then(response => response.json())
.then(response => {
Rjc.innerHTML = response.cloud_pct
Rjt.innerHTML = response.temp
Rjf.innerHTML = response.feels_like
Rjh.innerHTML = response.humidity
Rjmn.innerHTML = response.min_temp
Rjmx.innerHTML = response.max_temp
Rjws.innerHTML = response.wind_speed
Rjwd.innerHTML = response.wind_degrees
})
.catch(err => console.error(err));
}
const Weatherk = (city) => {
url = "https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city="+city
fetch(url, options)
.then(response => response.json())
.then(response => {
kc.innerHTML = response.cloud_pct
kt.innerHTML = response.temp
kf.innerHTML = response.feels_like
kh.innerHTML = response.humidity
kmn.innerHTML = response.min_temp
kmx.innerHTML = response.max_temp
kws.innerHTML = response.wind_speed
kwd.innerHTML = response.wind_degrees
})
.catch(err => console.error(err));
}
submit.addEventListener("click",(e)=>{
e.preventDefault()
Weather(cityname.value)
} )
Weather("Delhi")
Weatherm("Mumbai")
Weatherr("Ranchi")
Weatherk("Kolkata")
WeatherRj("Rajasthan")
lucknow.addEventListener("click",(e)=>{
e.preventDefault()
Weather("Lucknow")
} )
patna.addEventListener("click",(e)=>{
e.preventDefault()
Weather("Patna")
} )
bangalore.addEventListener("click",(e)=>{
e.preventDefault()
Weather("Bangalore")
} )