-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
41 lines (32 loc) · 996 Bytes
/
Copy pathscript.js
File metadata and controls
41 lines (32 loc) · 996 Bytes
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
/* const url = 'https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city='+ place; */
const options = {
method: 'GET',
headers: {
'X-RapidAPI-Key': '192c8ab208msh41b87a56fa39d0dp1f953cjsnd84f709614f2',
'X-RapidAPI-Host': 'weather-by-api-ninjas.p.rapidapi.com'
}
};
async function fetchData(place){
cityname.innerHTML=place;
const response = fetch('https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city='+ place, options)
.then(response => {
return response.json();
})
.then(response=>{
console.log(response);
temp.innerHTML = response.temp
feels.innerHTML=response.feels_like
clouds.innerHTML = response.cloud_pct
humidity.innerHTML=response.humidity
mintemp.innerHTML=response.min_temp
maxtemp.innerHTML=response.max_temp
})
.catch(err=>{
console.error('Error:', Error);
})
}
const btn=document.getElementById('search');
btn.addEventListener('click',(e)=>{
e.preventDefault()
fetchData(place.value);
})