/* reviewdesu.js this scripts proceeds to doing a review of the things you should know */ // UTILITY (copied from about.com) // thank you the internets Array.prototype.shuffle = function() { var s = []; while (this.length) s.push(this.splice(Math.random() * this.length, 1)[0]); while (s.length) this.push(s.pop()); return this; } var questions = []; var results = []; var question = []; var score = 0; var total = 0; var question_nb = 0; function start_review() { prepare_questions(); next_question(); } function prepare_questions() { for (var i = 0; i < batch_data.items.length; i++) { for (var j = 0; j < batch_data.columns.length; j++) { if (batch_data.columns[j].question == true) { var answer = ''; for (var k = 0; k < batch_data.items[i].length; k++) { if (k != j) answer += '
' + batch_data.items[i][k] + "
"; } questions.push({ "question": batch_data.items[i][j], "answer": answer, "key": batch_data.items[i][0], }); } } } total = questions.length; questions.shuffle(); } function next_question() { if (questions.length == 0) { score = Math.ceil(score * 100 / total); $("core").innerHTML = 'Finished. Score : ' + score + '/100. Saving data...
'; new Ajax.Request('index.php?p=brresults-study-' + batchid, { method: 'post', parameters: { score: score, results: Object.toJSON(results), }, onSuccess: function(transport) { $("core").innerHTML = 'Finished. Score : ' + score + '/100. ' + transport.responseText + '. back to batch
'; }, }); } else { question = questions[questions.length - 1]; questions.pop(); question_nb++; html = '' + question.question + '
'; html += ''; $("core").innerHTML = html; $("flipbtn").focus(); } } function show_answer() { html = '' + question.question + '
'; html += question.answer; html += ''; html += ''; html += '
'; $("core").innerHTML = html; $("dunnobtn").focus(); } function answer_question(a) { results.push([question.key, a]); score += a; next_question(); }