assets/JS/script.js
// ajax call to the Open Weather API to get forcasted data on selected city
ajax call to the Open Weather API to get forcasted data on selected city
ajax call to the Open Weather API to get forcasted data on selected city
function forecast(city) {
    var forecastURL = "https://api.openweathermap.org/data/2.5/forecast?q=" + city + "&appid=" + apiKey + "&units=imperial";
    $.ajax({
        url: forecastURL,
        method: "GET"
      }).then(function (forecastFiveDay) {
      console.log(forecastFiveDay);
      var forecastFiveDay = forecastFiveDay.list;
      $(document).ready(function() {
        $("#date").text(`(${moment().format("l")})`);
          for (i = 1; i < 7; i++) {
            var forecastDate = $(`#date${i}`);
            forecastDate.text(moment().add(`${i}`, "d").format("l"));
          };
          for (i = 0; i < forecastFiveDay.length; i++) {
              $("#forecastIcon" + i).attr("src", "https://openweathermap.org/img/wn/" + (forecastFiveDay[i].weather[0].icon) + ".png");
              $("#temp" + i).text("Temp: " + Math.round(forecastFiveDay[i].main.temp) + " °F");
              $("#rh" + i).text("Humidity: " + forecastFiveDay[i].main.humidity + "%");
            }
      });           
    })}
function forecast ( city ) { var forecastURL = "https://api.openweathermap.org/data/2.5/forecast?q=" + city + "&appid=" + apiKey + "&units=imperial" ; $ . ajax ( { url : forecastURL , method : "GET" } ) . then ( function ( forecastFiveDay ) { console . log ( forecastFiveDay ) ; var forecastFiveDay = forecastFiveDay . list ; $ ( document ) . ready ( function ( ) { $ ( "#date" ) . text ( ` ${ moment ( ) . format ( "l" ) } ` ) ; for ( i = 1 ; i < 7 ; i ++ ) { var forecastDate = $ ( ` ${ i } ` ) ; forecastDate . text ( moment ( ) . add ( ` ${ i } ` , "d" ) . format ( "l" ) ) ; } ; for ( i = 0 ; i < forecastFiveDay . length ; i ++ ) { $ ( "#forecastIcon" + i ) . attr ( "src" , "https://openweathermap.org/img/wn/" + ( forecastFiveDay [ i ] . weather [ 0 ] . icon ) + ".png" ) ; $ ( "#temp" + i ) . text ( "Temp: " + Math . round ( forecastFiveDay [ i ] . main . temp ) + " °F") ; $ ( "#rh" + i ) . text ( "Humidity: " + forecastFiveDay [ i ] . main . humidity + "%" ) ; } } ) ; } ) }
ajax call to the Open Weather API to get forcasted data on selected city
ajax call to the Open Weather API to get forcasted data on selected city