I'm trying to make an App for meteo, but my api doesn't load. When i call API in fetch it output: ReferenceError: API is not defined It is my first app (also my first question on StackOverflow), this is the snippet:
window.addEventListener('load', () =>{
let long;
let lang;
let temperatureDescription = document.querySelector('.temperature-description');
let temperatureDegree = document.querySelector('.temperature-degree');
let locationTimezone = document.querySelector('.location-timezone');
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position=>{
long = position.coords.longitude;
lat = position.coords.latitude;
const proxy = 'https://cors-anyware.herouapp.com/';
const API = '${proxy}https://api.openweathermap.org/data/2.5/forecast?id=524901&APPID=cc6a4a00070dfbee1327390b072f88d6/${lat},${long}';
});
fetch(API).then(response=>{
return response.json();
}).then(data=>{
console.log(data);
const {
temperature,
summary
}
= data.currently;
//set DOM elements from the API
temperatureDegree.textContent = temperature;
});
};
}
);
Can anyone help me? Thanks :)