You are viewing limited content. For full access, please sign in.

Question

Question

Grading Checkbox Question on Forms Quiz

asked on May 13, 2016

Hello all,

 

I am creating a quiz that has a few check box questions.  In order to get the check box questions correct, they must have only the correct answers checked. They will not be rewarded partial points for having some correct boxes checked but not all.

 

Can someone please help me with the javascript that would do this?

 

Thanks,
Dane

0 0

Answer

SELECTED ANSWER
replied on May 13, 2016

Here's a proof of concept using the code from this site.

$(document).ready(function () {

  $(".question1").change(function () {
    var q1bool = true
    var q1answers = new Array();
    var q1right = new Array('Red','Orange');
    $(".question1 input:checked").each(function(){
      q1answers.push($(this).val());
    });
    q1answers.sort();
    q1right.sort();
    if(q1answers.length == q1right.length) {
      for(i = 0; i < q1answers.length; i++) {
        if(q1answers[i] != q1right[i]) {
          q1bool = false;
          $(".q1result input").val("Incorrect")
          break;
        }
      }
    }
    else {
      q1bool = false;
      $(".q1result input").val("Incorrect")
    }
    if(q1bool == true) {
      $(".q1result input").val("Correct")
    }
  });
  
});

Just determine how you want to score the question when it's correct.

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.