Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add multiple correctIndex answers? #17

Closed
webb24h opened this issue Jan 3, 2022 · 2 comments
Closed

How to add multiple correctIndex answers? #17

webb24h opened this issue Jan 3, 2022 · 2 comments

Comments

@webb24h
Copy link

webb24h commented Jan 3, 2022

Hi, I'm trying to give a question multiple right answers but it doesn't work. How can I achieve this?

$('#quiz').quiz({
  questions: [
    {
      'q': 'A smaple question?',
      'options': [
        'Answer 1',
        'Answer 2',
        'Answer 3',
        'Answer 4'
      ],
      'correctIndex': ['1','2'],
      'correctResponse': 'Custom correct response.',
      'incorrectResponse': 'Custom incorrect response.'
    }
  ]
});
@webb24h webb24h changed the title How to add multiple answers? How to add multiple correctIndex answers? Jan 3, 2022
@jchamill
Copy link
Owner

jchamill commented Jan 26, 2022

This is currently not supported. I'd have to think through how this would work. Currently as soon as an answer is selected, feedback is provided (either correct or incorrect). With multiple, would it wait to provide feedback until all correct answers are selected? That could be confusing if the user doesn't know that multiple answers are allowed for certain questions. For now, you would need to add an additional option that says something like "c. Both a and b".

$('#quiz').quiz({
  questions: [
    {
      'q': 'A sample question?',
      'options': [
        'a. Answer 1',
        'b. Answer 2',
        'c. Answer 3',
        'd. Both a and b'
      ],
      'correctIndex': d,
      'correctResponse': 'Custom correct response.',
      'incorrectResponse': 'Custom incorrect response.'
    }
  ]
});

@webb24h
Copy link
Author

webb24h commented Jan 26, 2022

This is currently not supported. I'd have to think through how this would work. Currently as soon as an answer is selected, feedback is provided (either correct or incorrect). With multiple, would it wait to provide feedback until all correct answers are selected? That could be confusing if the user doesn't know that multiple answers are allowed for certain questions. For now, you would need to add an additional option that says something like "c. Both a and b".

$('#quiz').quiz({
  questions: [
    {
      'q': 'A sample question?',
      'options': [
        'a. Answer 1',
        'b. Answer 2',
        'c. Answer 3',
        'd. Both a and b'
      ],
      'correctIndex': d,
      'correctResponse': 'Custom correct response.',
      'incorrectResponse': 'Custom incorrect response.'
    }
  ]
});

Yes I understand. I tweaked your codes a little bit to adapt to my needs about a month ago. I like your tiny library and I'm presently using it as framework in one of my apps in which the questionnaire does not contain any wrong answer. It is more so like a survey type than it is a quiz test, if that makes sense. To make this work, I've made changes to thejquery.quiz.js.

This is a snippet from the setup line. I'm giving every answer an index of 1 by default :

[...]

setup: function() {

var quizHtml = '';

$.each(question.options, function(index, answer) {


index= 1;//giving all answers an index of 1 and setting correctIndex to 1 = every answer correct

quizHtml += '<li><a href="#" class="user_response" data-answer_type="'+question.type+'" data-answer="'+answer+'" data-index="' + index + '">' + answer + '</a></li>';


});

},

[...]

Then setting the correctIndex to 1 on every question will automatically make every answer correct following the logic :

$('#quiz').quiz({
  questions: [
    {
      'q': 'A smaple question?',
      'options': [
        'Answer 1',
        'Answer 2',
        'Answer 3',
        'Answer 4'
      ],
      'correctIndex': [1],
      'correctResponse': 'Custom correct response.',
      'incorrectResponse': 'Custom incorrect response.'
    }
  ]
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants