Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1.  
  2. registerMode('multiple-choice', {
  3.  
  4. validate: true,
  5.  
  6. validateAnswer: function(question){
  7. var correctAnswers = 0;
  8. var wrongAnswers = 0;
  9. $('#question').find('.answers .answer').each(function() {
  10. $(this).off('click');
  11. var answer_id = $(this).attr('data-answer-id');
  12. var selected = $(this).hasClass('active');
  13. if((question.answers[answer_id].correct && selected) || (!question.answers[answer_id].correct && !selected)) {
  14. correctAnswers++;
  15. } else {
  16. wrongAnswers++;
  17. }
  18. if(question.answers[answer_id].correct) {
  19. $(this).addClass('correct');
  20. } else {
  21. $(this).addClass('wrong');
  22. }
  23. });
  24.  
  25. var correct = wrongAnswers === 0 && correctAnswers > 0;
  26. if(correct) {
  27. $("#site .meta").removeClass("wrong");
  28. $("#site .meta").addClass("correct");
  29. } else {
  30. $("#site .meta").removeClass("correct");
  31. $("#site .meta").addClass("wrong");
  32. $("#check").removeClass("shake");
  33. setTimeout( function(){$("#check").addClass("shake");}, 100);
  34. }
  35.  
  36. showHint(false);
  37.  
  38. $("#check").unbind( "click" );
  39. $("#check").text("Weiter");
  40. $("#check").on("click", function(e){
  41. next();
  42. });
  43.  
  44.  
  45. return correct;
  46.  
  47. },
  48.  
  49. loadQuestion: function(question){
  50. var editArea = $('.meta #edit');
  51. var checkButton = $('#check');
  52. var questionContainer = $('#question');
  53. var hintContainer = $('#hint');
  54. var answersContainer = questionContainer.find('.answers');
  55.  
  56. if(question.edit_url) {
  57. editArea.attr('href', question.edit_url);
  58. editArea.show();
  59. } else {
  60. editArea.hide();
  61. }
  62.  
  63. checkButton.unbind( "click" );
  64. checkButton.text("Überprüfen");
  65. checkButton.on("click", function(){
  66. check();
  67. });
  68.  
  69. questionContainer.find('.question').html(question.question);
  70. answersContainer.html('');
  71. hintContainer.fadeOut(0);
  72. hintContainer.html(question.hint);
  73. for(var i = 0; i < question.answers.length; i++) {
  74. var answer = question.answers[i];
  75. answersContainer.append('<div class="answer choice" data-answer-id="' + i +'"><div class="tick"></div>'+ answer.answer +'</div>');
  76. }
  77.  
  78. questionContainer.find('.answers .answer').on('click',function() {
  79. $(this).toggleClass('active');
  80. });
  81.  
  82.  
  83.  
  84. },
  85.  
  86. init: function() {
  87. $('#hint-link').on('click',function() {
  88. if(window.lives > 0) {
  89. showHint(true);
  90. } else {
  91. alert("Du hast nicht genug Herzen, um einen Hinweis zur Hilfe anzeigen zu lassen.");
  92. }
  93. });
  94. }
  95.  
  96. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement