(function() {

function cookieQuestionCount() {
  var completedQuestions = docCookies.keys();
  return completedQuestions.length;
}

var questionCount = cookieQuestionCount() > 0 ? cookieQuestionCount() : 0;

function incrementSessionQuestionCount() {
    questionCount += 1;
}

// add check for cookies here
var answerArray = questions.map(function(questionObject) {
  questionObject.answer = false;
  return questionObject;
})

function updateAnswers(answer, questionNo) {
  answerArray[questionNo - 2].answer = answer;
}

function updateDoughnut(questionNo) {
  // find current topic
  var currentTopic = questions[questionNo - 2].topic;
  // find all the answer objects that match this topic
  var currentTopicAnswers = answerArray.filter(function(answerObject) {
    return answerObject.topic === currentTopic;
  });
  // length of array of current topic answers
  var currentTopicAllLength = currentTopicAnswers.length;
  // length of array of current topic true answers
  var currentTopicTrueLength = currentTopicAnswers.filter(function(answerObject) {
    return answerObject.answer === true;
  }).length;
  // percentage of current topic answered true
  var percentageTrueAnswers = currentTopicTrueLength / currentTopicAllLength;
  // percentage of doughnut it should take up
  var percentageOfDoughnut = percentageTrueAnswers * 100 / topics.length;
  if (questions[questionNo - 2].topic !== questions[questionNo - 1].topic) {
    config.data.labels.push('data #' + config.data.labels.length);
    config.data.datasets[0].data.push(percentageOfDoughnut);
    config.data.datasets[0].backgroundColor.push();
    window.myDoughnut.update();
  }
}

function changeTopic(questionNo) {
  if (questions[questionNo - 2].topic !== questions[questionNo - 1].topic) {
    $('h3.question-section-title').text(questions[questionNo - 1].topic);
    $('div.question-form').switchClass(questions[questionNo - 2].class, questions[questionNo - 1].class, 600);
  }
  if (questions[questionNo - 2].topic === 'Case Studies') {
    $('.question-section-title').css('visibility', 'hidden');
    $('.question-section-hr').css('visibility', 'hidden');
    $('.question-button').hide();
  }
}

function setCookie(answer, questionNo) {
  // check to see if cookie already exists and delete if it does
  docCookies.setItem(questions[questionNo - 2].question, answer);
}

function changeQuestion() {
  $.each($('.question-title'), function(index, question){
    if ($(question).is(':visible')) {
      $(question).toggle('slide', { direction: 'up' }, 600, function () {
        $(question).next().toggle('slide', { direction: 'down' }, 600);
      });
    }
  });
}

function showDesiredContent() {
  var trueAnswers = answerArray.filter(function(answerObject) {
    return answerObject.answer === true;
  }).map(function(object) {
    return object.question;
  });
  $.each($('.content'), function(index, content){
    var relatedQuestion = contentData.filter(function(contentObject) {
      return contentObject.title === content.id;
    }).map(function(object) {
      return object.question;
    })[0];
    if (trueAnswers.indexOf(relatedQuestion) >= 0) {
      content.setAttribute('style', 'display: block');
    }
  });
}

function enableButtons() {
  $.each($('.question-button'), function(index, button) {
    $(button).removeAttr("disabled");
  });
}

function disableButtons() {
  $.each($('.question-button'), function(index, button) {
    $(button).attr("disabled", true);
    setTimeout(function(){
      enableButtons();
    }, 1000);
  });
}

$('.question-button').click(function(event) {
  disableButtons();
  incrementSessionQuestionCount();
  var answer = event.target.id === 'question-button-yes'? true : false;
  updateAnswers(answer, questionCount);
  updateDoughnut(questionCount);
  changeTopic(questionCount);
  setCookie(answer, questionCount);
  changeQuestion();
  showDesiredContent();
  event.preventDefault();
});

})()

@@ -12,228 +12,82 @@
  %7B%0A%0A
-function cookieQuestionCount() %7B%0A  var completedQuestions = docCookies.keys();%0A  return completedQuestions.length;%0A%7D%0A%0Avar questionCount = cookieQuestionCount() %3E 0 ? cookieQuestionCount() : 0;%0A%0Afunction incrementSessionQ
+var questionCount = 0;%0A%0Afunction incrementSessionQuestionCount() %7B%0A  if (q
 uest
@@ -90,25 +90,29 @@
 uestionCount
-(
+ %3C 13
 ) %7B%0A    ques
@@ -131,40 +131,14 @@
  1;%0A
-%7D%0A%0A// add check for cookies here
+  %7D%0A%7D%0A
 %0Avar
@@ -2007,183 +2007,8 @@
 %0A%7D%0A%0A
-function setCookie(answer, questionNo) %7B%0A  // check to see if cookie already exists and delete if it does%0A  docCookies.setItem(questions%5BquestionNo - 2%5D.question, answer);%0A%7D%0A%0A
 func
@@ -3117,16 +3117,48 @@
  true);%0A
+    if (questionCount %3C 13) %7B%0A  
     setT
@@ -3182,16 +3182,18 @@
 %7B%0A      
+  
 enableBu
@@ -3205,16 +3205,18 @@
 ();%0A    
+  
 %7D, 1000)
@@ -3217,16 +3217,22 @@
  1000);%0A
+    %7D%0A
   %7D);%0A%7D%0A
@@ -3512,44 +3512,8 @@
 t);%0A
-  setCookie(answer, questionCount);%0A
   ch

version of website with cookies removed