Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
56 lines (50 loc) · 1.84 KB
/
Copy pathscript.js
File metadata and controls
56 lines (50 loc) · 1.84 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
50
51
52
53
54
55
56
const options = {
method: 'GET',
headers: {
'X-RapidAPI-Key': '7df487c521mshab83cab89b89281p13f2cfjsn2d324486f80e',
'X-RapidAPI-Host': 'weather-by-api-ninjas.p.rapidapi.com'
}
};
const GetWeather=(city)=>{
cityName.innerHTML=city
fetch('https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city=' + city, options)
.then(response => response.json())
.then((response) => {
console.log(response)
temp.innerHTML = response.temp
temp2.innerHTML = response.temp
feels_like.innerHTML = response.feels_like
humidity.innerHTML = response.humidity
humidity2.innerHTML = response.humidity
min_temp.innerHTML = response.min_temp
max_temp.innerHTML = response.max_temp
wind_speed.innerHTML = response.wind_speed
wind_speed2.innerHTML = response.wind_speed
wind_degrees.innerHTML = response.wind_degrees
sunrise.innerHTML = response.sunrise
sunset.innerHTML = response.sunset
})
.catch(error);
{
console.error(error);
}
}
submit.addEventListener("click",(e)=>{
e.preventDefault()
GetWeather(city.value)
})
GetWeather("Rourkela")
fetch('https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city=Delhi', options)
.then(response => response.json())
.then((response) => {
console.log(response)
tempDelhi.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 = response.sunrise
// sunset.innerHTML = response.sunset
})