-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
45 lines (30 loc) · 845 Bytes
/
Copy pathscript.js
File metadata and controls
45 lines (30 loc) · 845 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
35
36
37
38
39
40
41
42
43
const submit=document.getElementById('submit');
async function api(city) {
cityname.innerHTML=city
const url =
"https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city="+city;
const options = {
method: "GET",
headers: {
"X-RapidAPI-Key": "",
"X-RapidAPI-Host": "",
},
};
try {
const response = await fetch(url, options);
const result = await response.json();
temp.innerHTML = result.temp;
humidity.innerHTML = result.humidity;
min_temp.innerHTML = result.min_temp;
max_temp.innerHTML = result.max_temp;
} catch (error) {
console.error(error);
}
}
api("Bangalore");
submit.addEventListener('click',(e)=>{
e.preventDefault();
console.log(city.value)
api(city.value);
cityname.innerHTML=city.value;
})