W jaki sposób wyświetlić obrazek pobrany z api ?

0

Tak jak w temacie chodzi o 'icon' nie mam pomysłu appendChild(),textContent odpada, próbowałem coś z setAttribute, getAttribute ale nie wychodziło mi, może macie jakieś pomysły ?

const getPosition = () => {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition((position) => {
            const lat = position.coords.latitude;
            const long = position.coords.longitude;
            let yourWeather = `http://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${long}&APPID=${apikey}`;
            fetch(yourWeather)
                .then(function (response) {
                    return response.json();
                })
                .then(function (data) {
                    const icon = `http://openweathermap.org/img/w/${data.weather[0].icon}.png`;
                    cityTemp.textContent = data.main.temp;
                    cityWeather.textContent = data.weather[0].description;
                    weatherIcon.appendChild(icon);
                })
        });
    } else {
        alert("Nie można pobrać lokalizacji");
    }
}
getPosition();
1
const img = document.createElement('img').
img.src = `http://openweathermap.org/img/w/${data.weather[0].icon}.png`;
weatherIcon.appendChild(img);

1 użytkowników online, w tym zalogowanych: 0, gości: 1