Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions html/startAdvanced.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ <h3>Set up your quiz:</h3>
quizObject.title = $("#quizTitle").val();
quizObject.quiz = quiz;
var jsonString = JSON.stringify(quizObject);
jsonString = jsonString.replace(/"/g, "'");

$("#jsontextarea").val(jsonString);
}
Expand Down
93 changes: 93 additions & 0 deletions js/exam.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var QUESTION_COUNT = 1;

function ExamContext() {

this.answerKeyVisible = true;
Expand Down Expand Up @@ -74,6 +76,90 @@ function ExamContext() {

}

function updateAwesomeQuestions(seed)
{
$(".pa-question").each( function() {
var pa_params = $(this).data("pa-params");
pa_params = pa_params.replace(/'/g, '"');
var showPts = true; //$(this).data("pa-showPts") == "true"; TODO: don't hardcode true, figure out who comparison failing
var pts = $(this).data("pa-pts");
var ptsString = null;

if(showPts)
{
ptsString = "(" + pts + (pts == "1" ? "pt" : "pts") + ")";
}

var quizJson = JSON.parse(pa_params);
var quiz = new Quiz(seed, quizJson);

$(this).html((showPts ? ptsString : "") + quiz.formatQuestionsHTML() + "<br>" + quiz.formatAnswersHTML());
});

}

// data-pa-params="{'version':0.1,'title':'beef','quiz':[{'question':'cppBooleanEval','repeat':'1'}]}"
function makeQuestionJsonString(questionType)
{
var questionObject = "[{'question':'" + questionType + "','repeat':'1'}]";
var qStr = "{'version':0.1,'title':'Awesome Question','quiz':" + questionObject + "}";

return qStr;
}

function insertHtmlQuestion()//li, ta)
{
console.log("Button beep");
//$(li).html($(ta).value());
}

function addHtmlQuestion()
{
$(".theQuestions").append('<li class="html-question html-question' + QUESTION_COUNT + ' pageBreakBefore" data-pa-showPts="true" data-pa-pts="10">');

$(".html-question" + QUESTION_COUNT).html(
"<textarea id='textarea-html-question" + QUESTION_COUNT + "' rows='10' cols='50'>Enter question HTML here</textarea><br>" +
"<button id='button-html-question" + QUESTION_COUNT + "' type='button'>Insert question</button>"
);

var b = $(".button-html-question" + QUESTION_COUNT);
if(b === [])
{
console.log("Couldn't find the button.");
}
//.click(insertHtmlQuestion);
// function() {
// var liId = '#html-question' + QUESTION_COUNT;
// var taId = '#textarea-html-question' + QUESTION_COUNT;
// insertHtmlQuestion(liId, taId);
//});

QUESTION_COUNT++;
}

function addAwesomeQuestion()
{
var url = purl(); //Parse the current URL using the purl library
var seed = parseInt(url.param("start"));

var qJsonString = makeQuestionJsonString($('#awesomeQuestionType').val());
$(".theQuestions").append('<li class="pa-question pa-question' + QUESTION_COUNT + ' pageBreakBefore" data-pa-params="'+ qJsonString +'" data-pa-showPts="true" data-pa-pts="10">');

qJsonString = qJsonString.replace(/'/g, '"');
var qJson = JSON.parse(qJsonString);
var question = new Quiz(seed, qJson);

$(".pa-question" + (QUESTION_COUNT++)).html("(10 pst) " + question.formatQuestionsHTML() + "<br>" + question.formatAnswersHTML());
}

function showHideAnswers()
{
$(".pa-question-answer").each( function()
{
$(this).toggle();
});
}


$(document.body).ready(function () {

Expand All @@ -84,6 +170,13 @@ $(document.body).ready(function () {
var startExamNum = parseInt(url.param("start"));
var examCount = parseInt(url.param("count"));

addOptionForEachQuestionType($("#awesomeQuestionType"));
//updateAwesomeQuestions(startExamNum);

$("#htmlQuestionButton").click(addHtmlQuestion);
$("#awesomeQuestionButton").click(addAwesomeQuestion);
$("#showHideKey").click(showHideAnswers);

$(".showAnswerKey").click(function(){
ec.showAnswerKey();
});
Expand Down
7 changes: 4 additions & 3 deletions js/quiz.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//quiz.js -- handles the generation of the Quiz from a QuizDescriptor and a Seed,
//and the rendering of it as HTML
function Quiz(seed,quizDescriptor)
var Quiz = function Quiz(seed,quizDescriptor)
{
this.seed = seed;
this.jsonObject = quizDescriptor;
Expand All @@ -14,15 +14,16 @@ function Quiz(seed,quizDescriptor)
this.formatQuestionsHTML = function() {
var text = "";
for(var i=0; i<this.questions.length; i++)
text += "<h3>Question " + (i+1) + ":</h3>" + this.questions[i].formatQuestion("HTML") + "<br>";
// text += "<h3>Question " + (i+1) + ":</h3>" + this.questions[i].formatQuestion("HTML") + "<br>"; TODO: modified to use Awesome questions in exams
text += this.questions[i].formatQuestion("HTML") + "<br>";
return text;
}

//Create a string that is a list of all the answers
this.formatAnswersHTML = function() {
var text = "";
for(var i=0; i<this.questions.length; i++)
text += "<strong>" + (i+1) + ". </strong>" + this.questions[i].formatAnswer("HTML") + "<br>";
text += "<div class='pa-question-answer'><strong>Answer " + this.questions[i].formatAnswer("HTML") + "</strong></div>";
return text;
}

Expand Down