const iconElement = document.querySelector('.weather-icon'); const tempElement = document.querySelector('.temperature-value p'); const descElement = document.querySelector('.temperature-description p'); // App data const weather = {}; weather.temperature = { unit: 'celsius', }; const KELVIN = 273; // Use your own key for the Weather, Get it here: https://openweathermap.org/ const key = 'ba8b2c1103f42cc3ba33bb3a1c215385'; // Set Position function setPosition(); function setPosition(position) { // Here you can change your position // You can use https://www.latlong.net/ to get it! (I use San Francisco as an example) let latitude = 48.104340; let longitude = 20.791660; getWeather(latitude, longitude); } // Get the Weather data function getWeather(latitude, longitude) { let api = `https://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longitude}&appid=${key}`; console.log(api); fetch(api) .then(function (response) { let data = response.json(); return data; }) .then(function (data) { weather.temperature.value = Math.floor(data.main.temp - KELVIN); weather.description = data.weather[0].description; weather.iconId = data.weather[0].icon; }) .then(function () { displayWeather(); }); } // Display Weather info function displayWeather() { iconElement.innerHTML = ``; tempElement.innerHTML = `${weather.temperature.value}°C`; descElement.innerHTML = weather.description; }