-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (43 loc) · 1.47 KB
/
index.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
const options = {
method: 'GET',
headers: {
'X-RapidAPI-Key': '3daaae70c8msh48067969f825d70p1d8549jsnbf90168841c9',
'X-RapidAPI-Host': 'weather-by-api-ninjas.p.rapidapi.com'
}
};
async function getWeather(city) {
const url = 'https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city=' + city;
cityName.innerHTML = city;
try {
const response = await fetch(url, options);
const result = await response.json();
console.log(result);
cloud_pct.innerHTML = result.cloud_pct;
temp.innerHTML = result.temp;
temp2.innerHTML = result.temp;
humidity.innerHTML = result.humidity;
humidity2.innerHTML = result.humidity;
min_temp.innerHTML = result.min_temp;
max_temp.innerHTML = result.max_temp;
wind_speed.innerHTML = result.wind_speed;
wind_speed2.innerHTML = result.wind_speed;
wind_degrees.innerHTML = result.wind_degrees;
sunrise.innerHTML = result.sunrise;
sunset.innerHTML = result.sunset;
} catch (error) {
console.error(error);
}
}
// Add an event listener to the submit button
submit.addEventListener('click', (e) => {
e.preventDefault();
// const city = cityName.value; // Get the value of the search box
// getWeather(city);
getWeather(city.value)
});
getWeather("Chandigarh");
const myModal = document.getElementById('myModal')
const myInput = document.getElementById('myInput')
myModal.addEventListener('click', () => {
myInput.focus()
})