Skip to content

Instantly share code, notes, and snippets.

@matthewrknoll
Created January 19, 2017 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewrknoll/1a0624a841b10c3e5595ca6756f811d9 to your computer and use it in GitHub Desktop.
Save matthewrknoll/1a0624a841b10c3e5595ca6756f811d9 to your computer and use it in GitHub Desktop.
Beliefs Inventory - Self Grading Google Form
function onFormSubmit(e) {
//Gets the incoming form response
var formResponse = e.response;
//Puts the response from each question into an array
var itemResponses = formResponse.getItemResponses();
//Gets the respondent's email address
var email = formResponse.getRespondentEmail();
//Extracts the first and last name from the response
var name = itemResponses.splice(0, 2);
//An array containing how many dots are on the paper form in sequential order
var dots = [1,1,1,2,2,1,1,1,1,1,2,2,1,2,2,2,2,1,1,2,1,2,1,1,2,1,1,1,2,2,2,2,1,1,2,2,2,1,2,2,2,1,2,2,2,1,1,2,1,1,1,2,1,2,1,2,2,2,2,2,2,1,1,2,2,1,1,2,1,1,1,1,1,2,1,1,2,1,1,1,1,1,2,1,2,2,1,2,1,1,2,2,2,2,2,1,2,2,2,1];
//An empty array that will eventually contain final point values for each question
var scores =[];
//This loops through each question and calcualates a point value based on how the question was answered and how many dots were next to that question
for (i = 0; i < dots.length; i++) {
if (itemResponses[i].getResponse() == "Agree" && (dots[i] == 1)) {
scores.push(1);
}
else if (itemResponses[i].getResponse() == "Disagree" && (dots[i] == 2)) {
scores.push(1);
}
else {
scores.push(0);
}
};
//This loops through each of the above calcualted scores, adding together those questions specified by the answer key, storing each value in an array.
var finalScores = [];
for (j=0; j < 10; j++) {
var aFinalScore = [];
for (i=j; i < scores.length; i+=10) {
aFinalScore.push(scores[i]);
}
var aScore = aFinalScore.reduce(function(a, b) {
return a + b;
}, 0);
finalScores.push(aScore);
};
//Emails the form respondent the results of the beliefs inventory survey.
MailApp.sendEmail({
to: email,
subject: name[0].getResponse()+" "+name[1].getResponse()+"'s Beliefs Inventory Results",
htmlBody: "<strong>Beliefs Inventory Results</strong><br><br>" +
"<strong>1. Total: " + finalScores[0] + "/10</strong><br>" +
"The higher the total, the greater your agreement with the irrational idea that it is an absolute necessity for an adult to have love and approval from peers, family and friends.<br><br>" +
"<strong>2. Total: " + finalScores[1] + "/10</strong><br>" +
"The higher the total, the greater your agreement with the irrational idea that you must be unfailingly competent and almost perfect in all you undertake.<br><br>" +
"<strong>3. Total: " + finalScores[2] + "/10</strong><br>" +
"The higher the total, the greater your agreement with the irrational idea that certain people are evil, wicked and villainous, and should be punished.<br><br>" +
"<strong>4. Total: " + finalScores[3] + "/10</strong><br>" +
"The higher the total, the greater your agreement with the irrational idea that it is horrible when things are not the way you would like them to be.<br><br>" +
"<strong>5. Total: " + finalScores[4] + "/10</strong><br>" +
"The higher the total, the greater your agreement with the irrational idea that external events cause most human misery- people simply react as events trigger their emotions.<br><br>" +
"<strong>6. Total: " + finalScores[5] + "/10</strong><br>" +
"The higher the total, the greater your agreement with the irrational idea that you should feel fear or anxiety about anything that is unknown, uncertain or potentially dangerous.<br><br>" +
"<strong>7. Total: " + finalScores[6] + "/10</strong><br>" +
"The higher the total, the greater your agreement with the irrational idea that it is easier to avoid than to face life difficulties and responsibilities.<br><br>" +
"<strong>8. Total: " + finalScores[7] + "/10</strong><br>" +
"The higher the total, the greater your agreement with the irrational idea that you need something other or stronger or greater than yourself to rely on.<br><br>" +
"<strong>9. Total: " + finalScores[8] + "/10</strong><br>" +
"The higher the total, the greater your agreement with the irrational idea that the past has a lot to do with determining the present.<br><br>" +
"<strong>10. Total: " + finalScores[9] + "/10</strong><br>" +
"The higher the total, the greater your agreement with the irrational idea that happiness can be achieved by in action, passivity and endless leisure.",
noReply: true
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment