This repository was archived by the owner on Oct 11, 2024. It is now read-only.
forked from cs4241-18a/a1-gettingstarted
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha1scripts.js
More file actions
121 lines (109 loc) · 4.49 KB
/
a1scripts.js
File metadata and controls
121 lines (109 loc) · 4.49 KB
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
118
119
// Question objects
function question(text,type,responses,ans,wrong)
{
this.text = text;
this.type = type;
this.responses = responses;
this.ans = ans;
this.wrong = wrong;
}
var q1 = new question("Did Adam take CS 1102?","tf",
["True","False"],"True",
"Nope, I did freshman year");
var q2 = new question("Did Adam take CS 2301?","tf",["True","False"],"False", "Nope, I took 2303");
var q3 = new question("Did Adam take CS 3431?","tf",["True","False"],"True", "Yep, I did junior year");
var q4 = new question("Did Adam take CS 4432?","tf",["True","False"], "False", "Nope, I didn't");
var q5 = new question("What was Adam's favorite CS course as of Aug 2018?","multi",
["CS 1102","CS 2102","CS 3733","CS 4341"],
"CS 4341", "Nope, it was Soft. Eng. with Prof. Heineman");
var q6 = new question("What is Adam minoring in?","multi",
["Spanish","Data Science","English","ECE"],"Spanish",
"Nope, I'm minoring in Spanish");
var q7 = new question("What is Adam's executive role on the WPI sailing team?","multi",
["Rear Commodore","Treasurer","Commodore","Vice Commodore"], "Vice Commodore", "Nope, I'm the vice commodore (VP)");
var q8 = new question("What year is Adam?","multi",["Sophomore","Junior","Senior","Super Senior"], "Senior", "Nope, I'm a senior");
var q9 = new question("Does Adam play the guitar?","tf",["True","False"], "True", "Yep, I do");
var q10 = new question("What was Adam's first prog. language?","multi",
["Java","FORTRAN","C","Brainfuck"],"Java","No, it was Java");
var questions = [q1,q2,q3,q4,q5,q6,q7,q8,q9,q10];
var usedQuestions = [];
var activeQuestion;
var resetting = false;
var panel = document.getElementById('question-panel');
var button = document.getElementById('submit');
button.onclick =
function () {
hideButtons();
// Checks before question appears
if (resetting) // Reset after all questions done
resetSubmit();
if (panel.classList.contains('active')) { // reset animation
console.log("Active detected");
panel.classList.remove('active');
}
// Check if all questions completed
if (!questions.length) {
panel.innerHTML = "You've completed all questions!";
panel.classList.add('active');
changeSubmit();
return;
}
// Actual question
panel.classList.add('active'); // Make question div visible
randIndex = Math.floor(Math.random() * (questions.length)); // Pick random question
activeQuestion = questions[randIndex];
panel.innerHTML = questions[randIndex].text; // Fill question div
if (questions[randIndex].type === "tf") {
console.log("tf show");
} else {
console.log("multi show");
}
showButtons(questions[randIndex]);
usedQuestions.push(questions[randIndex]);
questions.splice(randIndex,1);
console.log(questions);
console.log(usedQuestions);
};
function showButtons(question) {
if (question.type === "tf") {
document.getElementById("choice-true").style.display = "inline";
document.getElementById("choice-true").innerHTML = "True";
document.getElementById("choice-false").style.display = "inline";
document.getElementById("choice-false").innerHTML = "False";
} else {
document.getElementById("choice1").style.display = "inline";
document.getElementById("choice1").innerHTML = question.responses[0];
document.getElementById("choice2").style.display = "inline";
document.getElementById("choice2").innerHTML = question.responses[1];
document.getElementById("choice3").style.display = "inline";
document.getElementById("choice3").innerHTML = question.responses[2];
document.getElementById("choice4").style.display = "inline";
document.getElementById("choice4").innerHTML = question.responses[3];
}
}
function hideButtons() {
document.getElementById("choice-true").style.display = "none";
document.getElementById("choice-false").style.display = "none";
document.getElementById("choice1").style.display = "none";
document.getElementById("choice2").style.display = "none";
document.getElementById("choice3").style.display = "none";
document.getElementById("choice4").style.display = "none";
}
function changeSubmit() {
button.innerHTML='Go Again!';
resetting = true;
}
function resetSubmit() {
button.innerHTML='New Question';
questions = usedQuestions;
usedQuestions = [];
resetting = false;
panel.classList.remove('active');
}
document.getElementById('choices').onclick=function(e) {
if (e.target.innerHTML !== activeQuestion.ans) {
alert(activeQuestion.wrong);
} else {
alert("Correct!");
}
}