ParcelJS how to dynamicly assing image in temple literal

Viewed 85

I in trying to change my background image based on value that is coming from API. So when from API value is 'partly-cloudy-night' i have same image name partly-cloudy-night.jpg to display. But.... As Parcel is working on statci assets i get this error

GET http://localhost:1234/assets/images/bg-images/partly-cloudy-day.jpg 404 (Not Found)

which is saying that image can't be found.

const displayWeatherData = (data, location) => {
     let {
           icon,
           summary
        } = data.currently

        document.querySelectorAll(".location-label").forEach(el =>
            el.innerHTML = location
        )

        document.querySelector('main').style.backgroundImage = 
        `url("./assets/images/bg-images/${icon}.jpg")` <== here
        }

    }
0 Answers
Related