function addCuisineVote() {
  const selectVal = document.getElementById("cuisine-select").value;
  if (selectVal !== "") {
    let userId = getCookie("userId");
    let cuisineVote = getCookie("cuisineVote");
    if (cuisineVote !== selectVal) {
      if (userId === "") {
        userId = Date.now().toString();
        document.cookie = 'userId=' + userId;
      }
      cuisineVote = selectVal;
      document.cookie = 'cuisineVote=' + selectVal;

      let cuisineVoteJson = {
          'userId': userId,
          'cuisineId': cuisineVote
      };

      fetch('/cuisine-data', {method: 'POST',
        headers: {'Content-Type': 'application/json'},
        body: JSON.stringify(cuisineVoteJson)
        }).then(response => response.text()).then((data) => {
          drawChart();
        })
    }
  }
}
/**
 * Adds the user's vote to the database and updates the chart accordingly. If the
 * user has already voted then their vote is just updated (this way they cannot vote twice).
 */
Adds the user's vote to the database and updates the chart accordingly. If the
user has already voted then their vote is just updated (this way they cannot vote twice).
Adds the user ' s vote to the database and updates the chart accordingly . If the user has already voted then their vote is just updated ( this way they cannot vote twice ) .
function addCuisineVote() {
  const selectVal = document.getElementById("cuisine-select").value;
  if (selectVal !== "") {
    let userId = getCookie("userId");
    let cuisineVote = getCookie("cuisineVote");
    if (cuisineVote !== selectVal) {
      if (userId === "") {
        userId = Date.now().toString();
        document.cookie = 'userId=' + userId;
      }
      cuisineVote = selectVal;
      document.cookie = 'cuisineVote=' + selectVal;
      let cuisineVoteJson = {
          'userId': userId,
          'cuisineId': cuisineVote
      };
      fetch('/cuisine-data', {method: 'POST',
        headers: {'Content-Type': 'application/json'},
        body: JSON.stringify(cuisineVoteJson)
        }).then(response => response.text()).then((data) => {
          drawChart();
        })
    }
  }
}
function addCuisineVote ( ) { const selectVal = document . getElementById ( "cuisine-select" ) . value ; if ( selectVal !== "" ) { let userId = getCookie ( "userId" ) ; let cuisineVote = getCookie ( "cuisineVote" ) ; if ( cuisineVote !== selectVal ) { if ( userId === "" ) { userId = Date . now ( ) . toString ( ) ; document . cookie = 'userId=' + userId ; } cuisineVote = selectVal ; document . cookie = 'cuisineVote=' + selectVal ; let cuisineVoteJson = { 'userId' : userId , 'cuisineId' : cuisineVote } ; fetch ( '/cuisine-data' , { method : 'POST' , headers : { 'Content-Type' : 'application/json' } , body : JSON . stringify ( cuisineVoteJson ) } ) . then ( response => response . text ( ) ) . then ( ( data ) => { drawChart ( ) ; } ) } } }
Adds the user's vote to the database and updates the chart accordingly.
Adds the user ' s vote to the database and updates the chart accordingly .