Search code examples
google-apps-scriptgoogle-forms

How to assign correct answers to checkboxGridItem questions in a quiz?


One issue with using Google Forms to make a multiple choice quiz is that if a question has (for example) 3 points and 3 out of 5 correct answers, if a student only selects 2 of the 3 correct answers they will get 0 points, not 2.

The workaround for this is to use a checkboxGrid with only 1 column where each row is an answer choice. Points can then be awarded for each correctly selected row.

I'm at a point where I want to create revision quizzes on the fly using this method, a snippet of my code that does this is here:

   var question = questions[Math.floor(Math.random() * questions.length)];
   var item = tasks.addCheckboxGridItem();
   item.setTitle(question[1]);
   item.setRows([ question[3],question[4],question[5],question[6],question,[7],question[8],question[9] ]);
   item.setColumns(['Click if correct']);

I'm at a loss as to assign the correct answer and points to specific rows. I can see how to do this for a simple multiple choice question but not for this checkBoxgrid.


Solution

  • Issue:

    GridItem and CheckboxGridItem currently don't support scoring. You cannot assign correct answers and points for these Items using Apps Script (e.g. createChoice(value, isCorrect), .setPoints(points)), nor retrieve this information (e.g. .isCorrectAnswer(), .getPoints(), .getScore()).

    Feature Request:

    There's currently a Feature Request related to this in Issue Tracker:

    I'd suggest you to click the star on the top-left of the page in order to keep track of this and to help priorizing it.

    Workaround:

    In the meantime, your only options would be to use the UI instead, or to write a grading function yourself, as explained in the referenced issue:

    - Find your Grid Item and grab it's ItemResponse.
    - Then get the response array.
    - Compare it to some grading function you create.
    - Return a score and use that number instead.

    Of course, this workaround wouldn't add the scoring system to the Form itself, but it would be a way to handle quiz points programmatically.