assets/script.js
// requestWeather - make call to weatherAPI for city
make call to weatherAPI for city
make call to weatherAPI for city
function requestWeather(city){
   var queryURL = `https://api.openweathermap.org/data/2.5/weather?q=${city}&units=imperial&appid=${apiKeyMap}`;
    $.ajax({
        url: queryURL,
        method: "GET"
      }).then(function(response) {
          var lat = response.coord.lat;
          var lon = response.coord.lon;
          requestForecast(lat, lon);
            var cityFormatted = currentCity.replace(/ /g, "_");
            storedCities = localStorage.getItem("cities") || "";
            if (storedCities == "") {
                localStorage.setItem('cities', cityFormatted);
            } else if (typeof storedCities === "string" && !storedCities.includes(cityFormatted)) {
                var x = [];
                x.push(storedCities, cityFormatted);
                localStorage.setItem('cities', x);
            } 
            displayCities();
            cityEl.val("");
            localStorage.setItem("lastCity", currentCity); 
      }).fail(function (error) { 
        $("form").trigger("reset");
        alert("City not found!");
      });
}
function requestWeather ( city ) { var queryURL = ` ${ city } ${ apiKeyMap } ` ; $ . ajax ( { url : queryURL , method : "GET" } ) . then ( function ( response ) { var lat = response . coord . lat ; var lon = response . coord . lon ; requestForecast ( lat , lon ) ; var cityFormatted = currentCity . replace ( / / g , "_" ) ; storedCities = localStorage . getItem ( "cities" ) || "" ; if ( storedCities == "" ) { localStorage . setItem ( 'cities' , cityFormatted ) ; } else if ( typeof storedCities === "string" && ! storedCities . includes ( cityFormatted ) ) { var x = [ ] ; x . push ( storedCities , cityFormatted ) ; localStorage . setItem ( 'cities' , x ) ; } displayCities ( ) ; cityEl . val ( "" ) ; localStorage . setItem ( "lastCity" , currentCity ) ; } ) . fail ( function ( error ) { $ ( "form" ) . trigger ( "reset" ) ; alert ( "City not found!" ) ; } ) ; }
requestWeather - make call to weatherAPI for city
requestWeather - make call to weatherAPI for city
// get coordinates from first query to maps //    console.log(queryURL); // replace spaces with underscores for storage // add cities to local storage, if already stored do not add // console.log(`not stored? ${!storedCities.includes(cityFormatted)}`); // console.log(localStorage.getItem('cities')); // display error message