title: Using one function to update an object value used by another function using jquery?
body: <p>I am writing a quiz app that references an object with values, everything is working well, even though this is beginner code.  Specifically, I want the first question to be replaced by the second question when the user clicks the "next question" button.  But while my nextQuestion() is increasing the variable in the object, it's not changing in the rest of the code.  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var quiz = { //the questions, you get the idea//
    correctCount: 0,
    currentQuestion: 0, //THIS IS WHAT I WANT TO UPDATE IN EACH ITERATION
    questions: [{
      question: "Question 1?",
      answers: ["A", "B", "C", "D"],
      correct: "A"
    }, {
      question: "Question 2?",
      answers: ["A", "B", "C", "D"],
      correct: "C"
    }]
  };
  
  $(document).ready(function() {
    $(".question").hide();
  
    //jquery event delegation
    function generateQuestion() {
      $("div.question").prepend(quiz.questions[quiz.currentQuestion].question);
      var answerList = quiz.questions[quiz.currentQuestion].answers;
      console.log(answerList);
      for (var i = 0; i &lt; answerList.length; i++) {
        $("ul").append("&lt;li&gt;" + answerList[i] + "&lt;/li&gt;");
      }
      console.log(quiz.currentQuestion);
    }
  
    function questionCheck() {
      $(".question-space").on('click', 'li', function(e) { //
        e.preventDefault();
        console.log($(this).val());
        if ($(this).text() === quiz.questions[quiz.currentQuestion].correct) {
          alert("Yes! The correct answer was " + quiz.questions[quiz.currentQuestion].correct + "!");
          quiz.correctCount += 1;
          $(".numCorrect").text(quiz.correctCount);
        } else {
          alert("Sorry! The correct answer was " + quiz.questions[quiz.currentQuestion].correct + "!");
        }
      });
    }
  
    function nextQuestion() {
      $(".next-question").on('click', function(e) {
        e.preventDefault();
        quiz.currentQuestion += 1;
        console.log(quiz.currentQuestion);
      });
    }
  
  
    //Event listeners
    $(".start-quiz").click((function() {
      $(".box").hide();
      $("div.question").show();
      generateQuestion();
      questionCheck();
      nextQuestion();
    }));
  
  });</code></pre>
  </div>
  </div>
  </p>