Skip to content

Instantly share code, notes, and snippets.

@strix
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save strix/015426b110fbb15331d9 to your computer and use it in GitHub Desktop.

Select an option

Save strix/015426b110fbb15331d9 to your computer and use it in GitHub Desktop.
Canvas Query Completed Quiz
// $('.text .question_text').text() // returns all the question text
// $('.display_question') // returns all q&a blocks
// $('.display_question.incorrect') // returns all incorrect q&a block
// $.get('url-to-js-file', function(data){eval(data)}); // to get and run the code
// localStorage.setItem('test', JSON.stringify({ 'one': 1, 'two': 2, 'three': 3 })) // saves stringified js object in localStorage
// JSON.parse(localStorage.getItem('test')) // gets and parses that object from localStorage
var printIt = function(arr){
for(var i=0; i<arr.length; i++){
console.log('Q: '+arr[i].q_text+'\n');
console.log('A: '+arr[i].a_text+'\n\n');
}
};
var rights = [],
wrongs = [];
$('.display_question').each(function(){
var incorrect = $(this).hasClass('incorrect'),
question_text = $(this).find('.question_text').text().trim(),
answer_text = $(this).find('.selected_answer .select_answer').text().trim(),
qaObj = {
'q_text': question_text,
'a_text': incorrect ? 'NOT '+answer_text : answer_text,
};
if(incorrect){
wrongs.push(qaObj);
} else {
rights.push(qaObj);
}
});
console.log(rights.length+' correct');
console.log(wrongs.length+' incorrect');
console.log('CORRECT:\n');
printIt(rights);
console.log('INCORRECT:\n');
printIt(wrongs);
@strix
Copy link
Author

strix commented Jan 21, 2015

Run this in the javascript console after completing a practice quiz on Canvas. It makes it a lot easier to record which ones you got right and wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment