0

I'm trying to create a quiz in the style of Buzzfeed. Is there a way to deactivate a part of the page when the user clicks on an answer, so that users can no longer click on alternative options of the same question and thus distort the final score of the test.

I've found some similar topics here and here but I don't want to add overlays and I'm not using inputs in my code so I was wondering if there is an alternative route.

I created a codepen here http://codepen.io/kkoutoup/pen/ByGEoQ

$(document).ready(function(){
//create an array to store correct answers
var totalCorrect = [];

$('li').click(function(){

    //caching variables
    var $parent = $(this).parent();
    var $span = $(this).find('.fa');
    //check for .correct class
        //if yes
        if($(this).hasClass('correct')){
            //add .correctAnswer class
            $(this).addClass('correctAnswer');
            //find next span and change icon
            $span.removeClass('fa fa-square-o').addClass('fa fa-check-square-o');
            //reduce opacity of siblings
            $(this).siblings().addClass('fade');
            //show answerText
            var $answerReveal= $parent.next('.answerReveal').show();
            var $toShowCorrect = $answerReveal.find('.quizzAnswerC');
            var $toShowFalse = $answerReveal.find('.quizzAnswerF');
            $toShowCorrect.show();
            $toShowFalse.remove();
            //add 1 to total correct array
            totalCorrect+=1;
            //get array's length
            var $finalScore = totalCorrect.length;
            console.log($finalScore);
        }else{
            //add .wrongAnswer class
            $(this).addClass('wrongAnswer').addClass('fade');
            //change icon
            $span.removeClass('fa fa-square-o').addClass('fa fa-check-square-o');
            //reduce opacity of its siblings
            $(this).siblings().addClass('fade');
            //show wrong Message
            var $answerReveal= $parent.next('.answerReveal').show();
            var $toShowCorrect = $answerReveal.find('.quizzAnswerC');
            var $toShowFalse = $answerReveal.find('.quizzAnswerF');
            $toShowCorrect.remove();
            $toShowFalse.show();
            //locate correct and add respective class
            $parent.find('.correct').addClass('correctAnswer');

        };
});
});//end dom ready

Any ideas?

Thanks

Community
  • 1
  • 1
  • So, when any one of the CB's (actually fake CB's) is selected, you'd want to disable the rest for that question no matter what the answer is? – lshettyl Mar 18 '15 at 11:21
  • @LShetty The correct answer is highlighted when the user clicks on any answer, whether right or wrong, so I want to prevent users from being able to click again on any of the
  • for that particular question because if they find the correct answer on the second on third try that would distort the final score of the quizz.
  • – Kostas Koutoupis Mar 18 '15 at 11:34
  • Right, how about the answers below? Do they help? – lshettyl Mar 18 '15 at 11:37
  • @LShetty Yep, it's working out fine! – Kostas Koutoupis Mar 18 '15 at 11:44