-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
38 lines (35 loc) · 1.14 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
const options = {
method: 'GET',
headers: {
'X-RapidAPI-Key': 'b3f155dcfdmshe28b590df70e807p1ad455jsn7bda3882d8fb',
'X-RapidAPI-Host': 'weather-by-api-ninjas.p.rapidapi.com'
}
};
const getWeatherData = (city) => {
console.log({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;
max_temp.innerHTML = response.max_temp;
min_temp.innerHTML = response.min_temp;
// cloud_pct.innerHTML = response.cloud_pct;
sunrise.innerHTML = response.sunrise;
sunset.innerHTML = response.sunset;
wind_degrees.innerHTML = response.wind_degrees;
wind_speed.innerHTML = response.wind_speed;
wind_speed2.innerHTML = response.wind_speed;
})
.catch(err => console.error(err));
}
submit.addEventListener("click", (event) => {
console.log(event.target.value)
event.preventDefault();
getWeatherData(city.value)
})