divcurlzero
divcurlzero

Reputation: 11

Automatically generating multiple choice quizzes on google forms

I am a teacher and need to create lots of multiple choice quizzes like this for my students.

You will see that each multiple choice question has exactly the same format - a question to be uploaded as an image and then followed by 4 multiple choice options - A, B, C and D.

My question is, is there any way to automate this process?

Each batch of questions are inside a googledrive folder and are named '1.png', '2.png', '3.png', etc - these are to be uploaded as images on the google form.

In a separate folder, I have a googlesheet listing all the answers to each question, it looks like this.

So the numbers that match with the answers (letters) in the spreadsheet correspond to the image files (eg. the first row of the spreadsheet above shows that the answer to question 1.png is A)

In a separate folder, I have another googlesheet, with feedback for both incorrect and correct answers which looks like this. Not all questions have feedback.

Is there anyway to automatically generate quizzes from these googlesheets and png files?

Thanks for taking the time to read through all this, and special thanks if you are able to suggest a solution?

Upvotes: 1

Views: 2747

Answers (2)

afif
afif

Reputation: 1

To over-come the problem in high densely populated area ultra dense network is suggested. Ultra dense network maintain a constant connectivity, data speed in highly populated area.

Upvotes: -1

Cooper
Cooper

Reputation: 64120

Here's a solution to a questioner that wanted to randomly select a given number of questions from a question bank. This doesn't utilize google forms but rather it uses html forms.

Here's the code (your welcome to adapt it): I had some questions on the code and corrected and problem and went in and updated the code. It's a little more organized and a bit easier to follow...I hope.

Code.gs:

function onOpen() {
    SpreadsheetApp.getUi().createMenu('Questions Menu')
      .addItem('Questions', 'launchQuestionsDialog')
      .addToUi();
}

question.gs

function getQuestions() {
  var ss=SpreadsheetApp.getActive();
  var cpData=getCpData();
  var qnum=cpData.qNum;
  var qa=getQAndA();
  var qi=getAnswerIndexes();
  var html='';
  var clr=['#f6d1ac','#c5e9bd'];
  for(var i=0;i<qa.length;i++) {
    html+=Utilities.formatString('<div id=d%s style="font-weight:bold;background-color:%s;padding:5px;"><span id="q%s">%s</span><input type="hidden" value="%s" class="hiding" />',qa[i][0],clr[i % 2],qa[i][0],qa[i][1],qa[i][0]);
    html+=Utilities.formatString('<input type="hidden" value="%s" class="hiding" />',qa[i][0]);
    for(var j=qi.firstIdx;j<=qi.lastIdx;j++) {
      if(qa[i][j]) {
        html+=Utilities.formatString('<br /><input type="radio" name="n%s" value="%s" />%s',qa[i][0],qa[i][j],qa[i][j]);
      }
    }
    html+='</div>'  
  }
  html+='<div id="controls"><br /><input type="button" value="Submit" onClick="recordData();" /></div>';
  return {html:html}
}

function launchQuestionsDialog() {
  var userInterface=HtmlService.createHtmlOutputFromFile('questions').setWidth(800).setHeight(500);
  SpreadsheetApp.getUi().showModelessDialog(userInterface, "The new Questions");
}

function selectTest() {
  var qA=selectQuestions(5,24);
  Logger.log(qA);
}

function selectQuestionIndexes(n,m) {
  var set=[];
  do {
    var i=Math.floor(Math.random()*(m));
    if(set.indexOf(i)==-1) {
      set.push(i);
    }
  }while(set.length<n);
  return set;
}

function getCpData() {
  var ss=SpreadsheetApp.getActive();
  var cpSh=ss.getSheetByName('ControlPanel');
  var cpRg=cpSh.getDataRange();
  var cpVa=cpRg.getValues();
  var qsrcSh=ss.getSheetByName(cpVa[1][0]);
  var adesSh=ss.getSheetByName(cpVa[1][1]);
  var qnum=cpVa[1][2];
  var cpData={'qSrc':cpVa[1][0],'aDes':cpVa[1][1],'qNum':cpVa[1][2]};
  return cpData;
}

function getAnswerIndexes() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getSheetByName(getCpData().qSrc);
  var rg=sh.getRange(1,1,1,sh.getLastColumn());
  var vA=rg.getValues();
  var re=/Answer \d{1,2}/i;
  var fidx=0;
  var lidx=0;
  var first=true;
  vA[0].forEach(function(e,i){if(String(vA[0][i]).match(re))if(first){fidx=i;first=false;}else{lidx=i;}});
  return {'firstIdx':fidx,'lastIdx':lidx};
}

function recordData(responses) {
  if(responses) {
    var ss=SpreadsheetApp.getActive();
    var sheetname=getCpData().aDes;
    var sh=ss.getSheetByName(sheetname);
    var ts=Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "MM/dd/yyyy HH:mm:ss"); 
    responses.forEach(function(e,i){e.splice(0,0,ts);sh.appendRow(e)});
  }
  return true;
}

function doGet() {
  return HtmlService.createHtmlOutputFromFile('questions');
}

function getQAndA() {
  var qa=[];
  var cma=',';
  var ss=SpreadsheetApp.getActive();
  var cpData=getCpData();
  var qsrcSh=ss.getSheetByName(cpData.qSrc);
  var qsrcRg=qsrcSh.getRange(2,1,qsrcSh.getLastRow()-1,qsrcSh.getLastColumn());
  var qsrcVa=qsrcRg.getValues();
  var qs=selectQuestionIndexes(cpData.qNum,qsrcVa.length);
  var aIdxs=getAnswerIndexes();
  for(var i=0;i<qsrcVa.length;i++) {
    var qas='';
    if(qs.indexOf(i)>-1) {
      qas+=qsrcVa[i][0] + cma + qsrcVa[i][1];
      for(j=aIdxs.firstIdx;j<=aIdxs.lastIdx;j++) {
        if(qsrcVa[i][j]) {
            qas+= cma + qsrcVa[i][j];
        }
      }
      qa.push(qas.split(cma));
    }
  }
  return qa;
}

questions.html:

<!DOCTYPE html>
<html>
<head>
 <!--<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>-->
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
 <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
 <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script>
    $(function() {
        google.script.run
        .withSuccessHandler(function(hObj){
          $('#container').html(hObj.html);
        })
        .getQuestions();
      });
    function recordData() {
      var responses=[];
      var cm=',';
      var divs = document.getElementsByTagName("div");
      for(var i=0;i<divs.length;i++) {
        var id=divs[i].getAttribute(['id']);
        var qnum=$('div#' + id + ' ' + 'input.hiding').val();
        //var question=document.getElementById(id).innerHTML;
        var question=$('#q' + qnum ).text(); 
        var answer=$('input[name="n' + qnum + '"]:checked').val();
        if(id!='controls') {
          if(!answer) {
            window.alert('You did not answer question number ' + Number(i+1) + '. It is a requirement of this survey that all questions must be answered.' );
            return;
          }else {
            var end='is near';
            var s=qnum + cm + question + cm + answer;
            responses.push(s.split(cm));
          }
        }
      }

      google.script.run
      .withSuccessHandler(displayThanks)
      .recordData(responses);
    }
    function displayThanks() {
      var divs = document.getElementsByTagName("div");
      for(var i=0;i<divs.length;i++) {
        divs[i].style.cssText="display:none;text-align:center";
      }
      var elemDiv = document.createElement('div');
      elemDiv.innerHTML="<br /><h1>Thank You For Your Participation in This Survey</h1>";
      document.body.appendChild(elemDiv);
    }
    console.log('My Code');
    </script>
    <style>
    #reply{display:none;}
    #collect{display:block;}
    body  {
    background-image: url("http://myrabridgforth.com/wp-content/uploads/blue-sky-clouds.jpg");
    background-color: #ffffff;
    background-repeat: no-repeat;
    background-position: left bottom;
    }
    </style>
</head>  
  <body>
    <div id="container">
    </div>
  </body>
</html>

Here's what the various tabs on the spreadsheet look like:

The ControlPanel Tab:

enter image description here

The QuestionBank Tab:

enter image description here

The Test1 Tab:

enter image description here

Hopefully this will be of some value to you.

Upvotes: 2

Related Questions