Would You Rather

by nukeboy212

HTML

<script src="https://www.gstatic.com/firebasejs/4.8.0/firebase.js"></script>
<h1>
Would you rather Game?
</h1>
<p id="question">
Would you rather eat a hershey's kiss sized poo or drink a gatorade bottle full of pee?
</p>
<button id="answer1">
Drink Pee
</button>
<button id="answer2">
Drink Non-pasturized Milk
</button>
<button id="reset">
Reset Data
</button>
<p id="results1">
Percentage of People Who Would Drink Pee:
</p>
<p id="results2">
Percentage of People Who Would Drink the Milk:
</p>

JavaScript

// Initialize Firebase
  var config = {
    apiKey: "AIzaSyC-vVInU2tHuaEa050Ld_i7tV_MsECSDMw",
    authDomain: "wouldurather-4828c.firebaseapp.com",
    databaseURL: "https://wouldurather-4828c.firebaseio.com",
    projectId: "wouldurather-4828c",
    storageBucket: "wouldurather-4828c.appspot.com",
    messagingSenderId: "721495623661"
  };
  firebase.initializeApp(config);
  var database = firebase.database();
  var question = database.ref("question");

  
  $("#answer1").click(function() {
var ref = firebase.database().ref("question");
ref.once("value")
  .then(function(snapshot) {
  var numVotes = snapshot.child("Drink Pee").child("Score").val();
   var other = snapshot.child("Drink Milk Straight From Utter").child("Score").val();

		ref.child("Drink Pee").child("Score").set(numVotes+1)
        numVotes = snapshot.child("Drink Pee").child("Score").val();
    console.log(numVotes)
 var total =  other + numVotes;
 console.log(total)
   $("#results1").text("Percentage of People That Would Drink Pee: " + parseInt((numVotes/total) *100) + "%")
$("#results2").text("Percentage of People That Would Drink the Milk: " + parseInt((other/total) *100) + "%")
  });

});
  $("#answer2").click(function() {
var ref = firebase.database().ref("question");
ref.once("value")
  .then(function(snapshot) {
  var numVotes = snapshot.child("Drink Milk Straight From Utter").child("Score").val();
       var other = snapshot.child("Drink Milk Straight From Utter").child("Score").val();

		ref.child("Drink Milk Straight From Utter").child("Score").set(numVotes+1)
    numVotes = snapshot.child("Drink Milk Straight From Utter").child("Score").val();
    console.log(numVotes)
 var total =  other + numVotes;  
  console.log(total)
   $("#results1").text("Percentage of People that would rather eat poo: " + parseInt((other/total) *100) + "%")
$("#results2").text("Percentage of People that would rather drink pee: " + parseInt((numVotes/total) *100) + "%")
 ...