JSFiddle - React, Tailwind, and code Playground

by markrummel

HTML

<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.1.1/css/bootstrap-combined.min.css">
<input type="text" id="movie-id" value="55555" /><br /><br />
<button id="yes" class="btn">Stay</button>
<button id="no" class="btn">Don't Stay</button><br /><br />
<button id="scenes" class="btn why">Extra Scenes</button>
<button id="outtatkes" class="btn why">Outtakes</button>
<button id="enhanced" class="btn why">Enhanced</button>
<button id="teaser" class="btn why">Sequel Teaser</button><br /><br />

<h1>Votes</h1>
<div id="results"></div>

JavaScript

alert('Enter Info');
$('button').click(function() {
  var type = $(this).attr('id');
  var movieID = $('#movie-id').val();
  var why = $(this).hasClass('why');
    
  alert(movieID);
    
  retrievedVotes = JSON.parse(localStorage.votes);
    
  if (type == 'yes' || type == 'no') {
    alert(type);
    if (retrievedVotes['movie' + movieID]['yes'] == '1' || localStorage['movie' + movieID]['no'] == '1') {
      alert("You've already Voted Yes or No");
      //redirect to Why Votes
    } 
      
    else {
      insertVote(type, movieID);
    }
    
  }//end YES/NO
         
  else if (why == true) {
    //alert('Step 2 Vote');       
    insertVote(type, movieID);
  }
                  
  function insertVote(type, movieID) {
    alert('Function Started');
    retrievedVotes = JSON.parse(localStorage.votes);
    alert(retrievedVotes);
    retrievedVote = retrievedVotes['movie' + movieID][type];
    if (retrievedVote != 1) {
      retrievedVotes['movie' + movieID][type] = 1;
      localStorage.votes = JSON.stringify(retrievedVotes);
    }
  }
});