-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
117 lines (108 loc) · 3.6 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*jslint es6:true*/
var questionIndex = 0;
var score = 0;
function loadFirstQuestion() {
$(".startQuiz").on("click", event =>
{
questionIndex = 0;
score = 0;
$(".question").css("display","block");
$(".question").css("visibility","visible");
$(".submitAnswer").css("display", "block");
$(".status").css("display","block");
$(".status").css("visibility","visible");
$(".feedback").css("visibility", "hidden");
$(".startPage").css("display", "none");
});
}
function nextQuestion(){
$(".nextQuestion").on("click", event =>
{
if (questionIndex < 9) {
questionIndex++;
$(updateQuestion);
$(".feedback").css("visibility", "hidden");
} else {
$(".feedback").css("visibility", "visible");
}
});
}
function verifyAnswer(){
$(".question").on("click", ".submitAnswer", event =>
{
var userAnswer = $( "input[type=radio][name=answerChoice]:checked").val();
if($('input[name=answerChoice]:checked').length<=0) {
alert("Please select an answer");
} else {if (userAnswer==questions[questionIndex].ansValue) {
$(correctAnswer);
} else {
$(incorrectAnswer);
}
if (questionIndex != 9) {
$(".submitAnswer").replaceWith("<button type='button' class='nextQuestion'>Next Question</button>");
} else {
$(".submitAnswer").css("display", "none");
$(".startOver").css("display", "block");
$(".feedback").css("visibility", "visible");
$(startOver);
}
$("input[type=radio]").attr('disabled', true);
$(nextQuestion);
}
});
}
function updateQuestion() {
var questionNumber = (questionIndex + 1).toString();
$(".questionNumber").text(questionNumber);
$(".expression").html("<p>"+questions[questionIndex].question+"</p>");
$("label[for='answer1']").html(questions[questionIndex].ans1);
$("label[for='answer2']").html(questions[questionIndex].ans2);
$("label[for='answer3']").html(questions[questionIndex].ans3);
$("label[for='answer4']").html(questions[questionIndex].ans4);
$("input[name=answerChoice]").attr("checked",false);
$(loadMathJax(".question"));
$(".nextQuestion").replaceWith("<button type='submit' class='submitAnswer'>Submit</button>");
$("input[type=radio]").attr('disabled', false);
}
function correctAnswer() {
$(".feedback").text("Correct!");
score ++;
var updatedScore = score.toString();
$(".currentScore").text(updatedScore);
$(".feedback").css("visibility", "visible");
$(".feedback").css("color", "#0e492d");
}
function incorrectAnswer() {
var correctAnswer = questions[questionIndex].answer;
$(".feedback").html("<p>Your Answer is incorrect. The correct answer is: "+correctAnswer+"</p>");
$(loadMathJax(".feedback"));
$(".feedback").css("color", "#c20000");
}
//This hides the underlying notation while MathJax processes the typsetting
function loadMathJax(targetClass) {
$(targetClass).css("visibility","hidden");
$(targetClass).load("/MathjaxTesting.aspx", function () {
MathJax.Hub.Queue(["Typeset",MathJax.Hub, targetClass],
function () {
$(targetClass).css("visibility","visible");
});
});
}
function startOver() {
$(".startOver").on("click", event =>
{
questionIndex = 0;
score = 0;
$(updateQuestion);
var updatedScore = score.toString();
$(".question").css("display", "none");
$(".currentScore").text(updatedScore);
$(".startPage").css("display", "block");
$(".status").css("display", "none");
$(".startOver").css("display", "none");
});
}
$(document).ready(function() {
$(loadFirstQuestion);
$(verifyAnswer);
});