-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
30 lines (23 loc) · 835 Bytes
/
main.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
const cityName = document.getElementById('cityname');
const submitBtn = document.getElementById('submitBtn');
const city_name = document.getElementById('city_name');
const getInfo = async(event) =>
{
console.log("pouyy")
event.preventDefault();
let cityVal = cityName.value;
if(cityVal === ""){
city_name.innerText = `Please write the name before search`;
}else{
try{
let url = `http://api.openweathermap.org/data/2.5/weather?q=${cityVal}&units=metric&appid=647db17c0535eefdadd25a8659b40531`;
const response = await fetch(url);
console.log(response);
}catch{
console.error(error);
city_name.innerText = `Please write the city name properly`;
}
}
// alert('Hii');
}
submitBtn.addEventListener('click', getInfo);