Weather API - Feedback

Hello,

I had just finished my weather API.

I’m actually using 2 APIs, one to determine the local weather, while the other is to determine weather by zip code.

Please let me know how I can improve the code and it’s organization. I’m not sure if my approach to setting the background image is even a good practice – using the .includes() method.

Thanks in advance!

That seems like a lot of includes and that is not even all the possible weather conditions that can be returned from that API.

Below is another possible solution using just one include. There are

    var backgroundImage = function(desc){
      desc = desc.toLowerCase();
      var conditionBGs = {
        clear: 'http://www.gazetteseries.co.uk/resources/images/3972423.jpg?display=1&htype=0&type=responsive-gallery',
        cloud: 'http://www.gazetteseries.co.uk/resources/images/3972423.jpg?display=1&htype=0&type=responsive-gallery',
        rain: 'https://d2v9y0dukr6mq2.cloudfront.net/video/thumbnail/D8qa-2E/city-skyline-background-on-a-rainy-wet-weather-day-sad-mood-depressive_hziovexr__F0000.png',
        sun: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTtU4OgjoEslIOLAOW-OUZhydVt-Ohx1W3SLxHeDW1KFv9N7GCG',
        snow: 'https://i.pinimg.com/originals/e1/c5/49/e1c549a8e5b3ba9415e45daed819cc75.jpg'
      };
      var bg; // would be good to assign a default image in case a desc does not match any of the above
      for (condition in conditionBGs) {
        if (desc.includes(condition)) {
          bg = conditionBGs[condition];
          break;
        }
      }
      $("body").css("background-image", "url(" + bg + ")");
    }

Also, what if it is night and the description is Clear? Do you really want to show a sunny sky?