(function ($, root, undefined) { $(function () { $(document).click(function(event){ console.log('body click'); collectAnswers(false); collectThesisAnswers(false); $('.correctanswer-tooltip').tooltip().hide(); $('.correctanswer-text').hide(); $('.explanation-text').hide(500); $('#check-answers').show(); }); 'use strict'; // DOM ready, take it away const checkButton = $('#check-answers'); // variable used to check if button needs to be enabled let questionsAnswered = true; // all questions let questions = $('.question'); let theses = $('.thesis'); // check an answer function checkAnswer(answer) { let input = answer.find('input'); let answerLabel = answer.find('label'); let correctAnswer = $(input).data('answer'); if (correctAnswer == 'correct-answer') { answerLabel.addClass('correct'); if ($(input).is(':checked')) { answerLabel.addClass('right'); } } else { answerLabel.addClass('incorrect'); if ($(input).is(':checked')) { answerLabel.addClass('wrong'); } } } // uncheck an answer function unCheckAnswer(answer) { let input = answer.find('input'); let answerLabel = answer.find('label'); let correctAnswer = $(input).data('answer'); if (correctAnswer == 'correct-answer') { answerLabel.removeClass('correct'); if ($(input).is(':checked')) { answerLabel.removeClass('right'); } } else { answerLabel.removeClass('incorrect'); if ($(input).is(':checked')) { answerLabel.removeClass('wrong'); } } } // check if all questions are answered function allQuestionsAnswered() { questionsAnswered = true; // loop through questions questions.each(function () { if (!$(this).find('input:checked').length > 0) { questionsAnswered = false; } }); if (questionsAnswered == true) { checkButton.removeClass('inactive'); } } // check on page load allQuestionsAnswered(); // collect all answers function collectThesisAnswers(check=true) { console.log('welcome'); // loop through questions theses.each(function () { // collect all answers let answers = $(this).map(function () { return $(this).find('.answer'); }).get(); // loop through answers for (let i = 0; i <= answers.length; i++) { if (answers[i] !== undefined) { let allAnswers = answers[i]; allAnswers.each(function () { // answer let answer = $(this); if (check == true) { checkAnswer(answer); } else { unCheckAnswer(answer) } }); } } }); } // collect all answers function collectAnswers(check=true) { // loop through questions questions.each(function () { // collect all answers let answers = $(this).map(function () { return $(this).find('.answer'); }).get(); // loop through answers for (let i = 0; i <= answers.length; i++) { if (answers[i] !== undefined) { let allAnswers = answers[i]; allAnswers.each(function () { // answer let answer = $(this); if (check == true) { checkAnswer(answer); } else { unCheckAnswer(answer) } }); } } }); } // check answers on button click checkButton.click(function(event){ event.stopPropagation(); $(this).hide(); if(theses.length > 1 ) { collectThesisAnswers(true); } else { collectAnswers(true); } $('.correctanswer-tooltip').tooltip().show(); $('.correctanswer-text').show(); $('.explanation-text').show(500); }); // make next question active let questionInputs = $('.answer input'); questionInputs.click(function () { let parent = $(this).closest('.question'); let nextQuestion; if ($(parent).next().is('.question')) { nextQuestion = parent.next('.question'); } else { nextQuestion = $('.second-column .question').first(); } nextQuestion.removeClass('inactive'); allQuestionsAnswered(); }); }); })(jQuery, this); /*******************************************************************/ /* ftrtch dino */ /* [type: JS] [file:ilearn-check-button] [166.942] DESIGN*/ /*******************************************************************/ /* 0.7 D>D */ /* db 174 */