-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
150 lines (133 loc) · 3.96 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
'use strict';
let i = 0;
let questionNumber = i + 1;
let score = 0;
function generateWelcomePage() {
console.log("Generating getting started page");
return `
<div class="landing-zone js-landing-zone">
<div class="quiz-about-panel">
<h2>macOS® Basics</h2>
<h3>Photos App</h3>
</div>
<button class="get-started-button js-get-started-button">Get Started</button>
</div>`;
}
function getStarted() {
console.log('`getStarted` ran')
const welcomePage = generateWelcomePage();
$('.js-landing-zone').html(welcomePage);
$('.js-landing-zone').on('click', '.js-get-started-button', function() {
const renderedQuestion = generateQuestionDisplay();
$('.js-landing-zone').html(renderedQuestion);
})
}
function generateQuestion() {
console.log("Generating all of question form");
let quizChef = $(`
<form class="js-generated-quiz ram">
<fieldset class="js-landing-zone ram">
<legend>${STORE[i].question}
</legend>
</fieldset>
</form>`)
let cookIngredients = $(quizChef).find('fieldset');
STORE[i].choices.forEach(function (answerValue, answerIndex) {
$(`
<input type="radio" id="${answerIndex}" name="answer" value="${answerValue}" required>
<label for="${answerIndex}">${answerValue}</label>
`).appendTo(cookIngredients);
});
$(`<button type="submit" class="submit js-submit-quiz-answer" value="Submit">Submit</button>`).appendTo(cookIngredients);
$(`<ul class="entire-status-bar">
<li class="status-bar-third" id="right-wrong">Question:
<span class="questionNumber">${questionNumber}</span>/10</li>
<li class="status-bar-third" id="empty-third"></li>
</li>
<li class="status-bar-third">Score:
<span class="score">${score}</span>
</li>
</ul>`).appendTo(cookIngredients)
return quizChef;
}
function generateQuestionDisplay() {
console.log('`questionDisplayInterface` ran')
if (i < STORE.length) {
return generateQuestion();
} else {
$('.js-landing-zone').hide();
finalScore();
$('.questionNumber').text(10);
}
}
function quizMain() {
console.log('`quizMain` ran')
$('.js-landing-zone').on('click', '.js-submit-answer', function() {
// $('.js-landing-zone').hide();
// $('.js-landing-zone').show();
const nextQuestion = generateQuestionDisplay();
$('.js-landing-zone').html(nextQuestion);
})
}
function correct() {
console.log('`correct` ran')
if (i < 10) {
i++
} else {
stop
}
console.log(i)
}
function incorrect() {
console.log('`incorrect` ran')
if (i < 10) {
i++
} else {
stop
}
console.log(i)
}
function questionResult() {
console.log('`questionResult` ran')
$('.js-landing-zone').on('submit', '.js-generated-quiz', function(e) {
e.preventDefault()
console.log(STORE[i].answer, "TEST")
console.log(i)
if ($('input:checked').val() === STORE[i].answer) {
correct();
} else {
incorrect();
}
});
quizMain();
}
function finalScore() {
if (score >=8) {
alert("you rock!")
} else if (score >= 5) {
alert("Study!...but you passed")
} else {
// return `
// <div class="landing-zone js-landing-zone">
// <div class="quiz-about-panel">
// <h2>macOS® Basics</h2>
// <h3>Photos App</h3>
// </div>
// <button class="restart-quiz">Restart</button>
// </div>`;
alert("You failed, please try again")
}
}
function restart() {
console.log('`restart` ran')
}
function quizComplete() {
getStarted();
//complete
quizMain();
//complete
questionResult();
//in-progress
restart();
}
$(quizComplete);