function ajaxFunction() {

  $.ajax(toggleVariable).then(stuffThatComesBack => {

    stuffThatComesBack.forEach((animal) => {
      Animals.animalsArray.push(new Animals(animal.title, animal.image_url, animal.description, animal.keyword, animal.horns));
    });
    // console.log(Animals.animalsArray);

    //New animal constructor complete, code is finished, next step is Animals.animalsArray that we made loops through and calls render function at each instance of loop
    const filterKeyword = [];

    Animals.animalsArray.forEach((animal) => {

      // populate filter
      if (!filterKeyword.includes(animal.keyword)) {
        const $option = $(`<option>${animal.keyword}</option>`);
        $option.attr('value', animal.keyword);
        $('select').append($option);
        filterKeyword.push(animal.keyword);
      }

      // console.log(filterKeyword);
      animal.render();

    });
  });
  $('.sort').on('click', (event) => {
    event.preventDefault();
    let sortingBy;
    if ($(event.target).text() === 'Sort by Title'){
      sortingBy = 'title';
    } else {
      sortingBy = 'horns';
    }
    //sort by alphabet
    Animals.animalsArray.sort((left, right) => {
      $('div').remove();
      if (left[sortingBy] < right[sortingBy]) {
        return -1;
      } else if (left[sortingBy] > right[sortingBy]) {
        return 1;
      } else {
        return 0;
      }
      // console.log(Animals.animalsArray);
    });
    Animals.animalsArray.forEach(animal => animal.render());
  });
}
// ajax retrieves objects from json file and puts it in new array, calls render function
ajax retrieves objects from json file and puts it in new array, calls render function
ajax retrieves objects from json file and puts it in new array calls render function
function ajaxFunction() {
  $.ajax(toggleVariable).then(stuffThatComesBack => {
    stuffThatComesBack.forEach((animal) => {
      Animals.animalsArray.push(new Animals(animal.title, animal.image_url, animal.description, animal.keyword, animal.horns));
    });
    const filterKeyword = [];
    Animals.animalsArray.forEach((animal) => {
      if (!filterKeyword.includes(animal.keyword)) {
        const $option = $(`<option>${animal.keyword}</option>`);
        $option.attr('value', animal.keyword);
        $('select').append($option);
        filterKeyword.push(animal.keyword);
      }
      animal.render();
    });
  });
  $('.sort').on('click', (event) => {
    event.preventDefault();
    let sortingBy;
    if ($(event.target).text() === 'Sort by Title'){
      sortingBy = 'title';
    } else {
      sortingBy = 'horns';
    }
    Animals.animalsArray.sort((left, right) => {
      $('div').remove();
      if (left[sortingBy] < right[sortingBy]) {
        return -1;
      } else if (left[sortingBy] > right[sortingBy]) {
        return 1;
      } else {
        return 0;
      }
    });
    Animals.animalsArray.forEach(animal => animal.render());
  });
}
function ajaxFunction ( ) { $ . ajax ( toggleVariable ) . then ( stuffThatComesBack => { stuffThatComesBack . forEach ( ( animal ) => { Animals . animalsArray . push ( new Animals ( animal . title , animal . image_url , animal . description , animal . keyword , animal . horns ) ) ; } ) ; const filterKeyword = [ ] ; Animals . animalsArray . forEach ( ( animal ) => { if ( ! filterKeyword . includes ( animal . keyword ) ) { const $option = $ ( ` ${ animal . keyword } ` ) ; $option . attr ( 'value' , animal . keyword ) ; $ ( 'select' ) . append ( $option ) ; filterKeyword . push ( animal . keyword ) ; } animal . render ( ) ; } ) ; } ) ; $ ( '.sort' ) . on ( 'click' , ( event ) => { event . preventDefault ( ) ; let sortingBy ; if ( $ ( event . target ) . text ( ) === 'Sort by Title' ) { sortingBy = 'title' ; } else { sortingBy = 'horns' ; } Animals . animalsArray . sort ( ( left , right ) => { $ ( 'div' ) . remove ( ) ; if ( left [ sortingBy ] < right [ sortingBy ] ) { return - 1 ; } else if ( left [ sortingBy ] > right [ sortingBy ] ) { return 1 ; } else { return 0 ; } } ) ; Animals . animalsArray . forEach ( animal => animal . render ( ) ) ; } ) ; }
ajax retrieves objects from json file and puts it in new array, calls render function
ajax retrieves objects from json file and puts it in new array calls render function
// console.log(Animals.animalsArray); //New animal constructor complete, code is finished, next step is Animals.animalsArray that we made loops through and calls render function at each instance of loop // populate filter // console.log(filterKeyword); //sort by alphabet // console.log(Animals.animalsArray);