-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (32 loc) · 1.04 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
console.log("Aditya Mishra");
const API_KEY = "bf36bb65863c52205400712b61d7ccf8";
function fetchWeatherInfo(data){
let newPara = document.createElement('p');
newPara.textContent = `${data?.main?.temp.toFixed(2)} °C`;
document.body.appendChild(newPara);
}
async function fetchWeatherDetails(){
try{
let city = "goa";
const response = await fetch(`https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${API_KEY}&units=metric`);
const data = await response.json();
console.log("Weather data:-> ", data);
fetchWeatherInfo(data);
}
catch(err){
console.log("Error Found",err);
}
}
async function getCustomWeatherDetails(){
try{
let lat = 56.4556;
let lon = 87.9545;
let result = await fetch(`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${API_KEY}`);
let data = await result.json();
console.log(data);
fetchWeatherInfo(result);
}
catch(err){
console.log("Error Found", err);
}
}