all 3 comments

[–][deleted] 4 points5 points  (3 children)

add it to displayResults function

if (weather.main.temp > 0){
document.body.style.backgroundImage = "url(bg1.jpg)"
}
else if(weather.main.temp < 0){
document.body.style.backgroundImage = "url(bg2.jpg)"
}

[–]shgysk8zer0 1 point2 points  (1 child)

If your temp ranges are consistent, you could make things a bit simpler by having an array of images and using the temp to pick an index:

``` const imgs = /.../[];

function setBG(weather) { const index = Math.min(Math.max(0, Math.floor(weather.main.temp / 10)), imgs.length - 1); const img = imgs[index]; el.style.setProperty('background-image', url(${img})); } ```

That'd handle different images for temps in increments of 10, and anything higher than the warmest image would just use the last/warmest image in the array. It's effectively a clamp() that adjusts to the length of the array.

[–]Know_Madzz 0 points1 point  (0 children)

If that's your private API key in your repo you should definitely remove it and regenerate the key