script.js
// Display and save the search history of cities
Display and save the search history of cities
Display and save the search history of cities
function searchHistory(searchValue) {
    if (searchValue) {
        if (cityList.indexOf(searchValue) === -1) {
            cityList.push(searchValue);
            listArray();
            clearHistoryButton.removeClass("hide");
            weatherContent.removeClass("hide");
        } else {
            var removeIndex = cityList.indexOf(searchValue);
            cityList.splice(removeIndex, 1);
            cityList.push(searchValue);
            listArray();
            clearHistoryButton.removeClass("hide");
            weatherContent.removeClass("hide");
        }
    }
}
function searchHistory ( searchValue ) { if ( searchValue ) { if ( cityList . indexOf ( searchValue ) === - 1 ) { cityList . push ( searchValue ) ; listArray ( ) ; clearHistoryButton . removeClass ( "hide" ) ; weatherContent . removeClass ( "hide" ) ; } else { var removeIndex = cityList . indexOf ( searchValue ) ; cityList . splice ( removeIndex , 1 ) ; cityList . push ( searchValue ) ; listArray ( ) ; clearHistoryButton . removeClass ( "hide" ) ; weatherContent . removeClass ( "hide" ) ; } } }
Display and save the search history of cities
Display and save the search history of cities
// Grab value entered into search bar  // var searchValue = searchCityInput.val().trim(); // If there are characters entered into the search bar // Place value in the array of cities // if it is a new entry // List all of the cities in user history // Remove the existing value from // the array // Push the value again to the array // list all of the cities in user history // so the old entry appears at the top // of the search history // console.log(cityList);