-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom.js
82 lines (65 loc) · 1.62 KB
/
custom.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
var header = document.getElementById('header');
var content = document.getElementById('content-div');
var footer = document.getElementById('footer');
var qCount = 0;
document.getElementById('begin').onclick = function () {
initializeQuiz();
}
function initializeQuiz() {
while(header.hasChildNodes()) {
header.removeChild(header.lastChild);
}
while(content.hasChildNodes()) {
content.removeChild(content.lastChild);
}
loadNextContent();
}
/*Content logic*/
function loadContent() {
loadQuestion();
loadButtons();
}
function loadPreviousContent() {
qCount = qCount - 2;
loadContent();
qCount++;
}
function loadNextContent() {
loadContent();
qCount++;
}
/*End of content logic*/
/*Question logic*/
function loadQuestion() {
console.log('question loaded');
}
/*End of question logic*/
/*Button logic*/
function loadButtons() {
if(qCount > 0 && !document.getElementById('back')) {
loadButton('back');
} else if (qCount <= 0 && document.getElementById('back')) {
removeButton('back');
}
if(!document.getElementById('next')) {
loadButton('next');
}
}
function loadButton(name) {
var button = document.createElement('input');
button.type = 'button';
button.setAttribute('value', name.toUpperCase());
button.setAttribute('id', name);
if(name === 'back') {
button.addEventListener('click', loadPreviousContent);
footer.insertBefore(button, document.getElementById('next'));
} else {
button.addEventListener('click', loadNextContent);
footer.appendChild(button);
}
}
function removeButton(name) {
var button = document.getElementById(name);
button.parentNode.removeChild(button);
}
/*End of button logic*/