-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresults-screen.js
60 lines (56 loc) · 2.11 KB
/
results-screen.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
// TODO(you): Modify the class in whatever ways necessary to implement
// the flashcard app behavior.
//
// You may need to do things such as:
// - Changing the constructor parameters
// - Adding methods
// - Adding additional fields
class ResultsScreen {
constructor(containerElement) {
this.containerElement = containerElement;
document.querySelector(".to-menu").addEventListener('click', function() {
document.querySelector(".correct").textContent = "";
document.querySelector(".incorrect").textContent = "";
app.results.hide();
app.flashcards.hide();
app.menu.show();
}, false);
}
show(numberCorrect, numberWrong) {
this.containerElement.classList.remove('inactive');
console.log(numberCorrect + numberWrong);
let perc = Math.round(numberCorrect/(numberCorrect + numberWrong)*100);
document.querySelector(".percent").textContent = perc;
document.querySelectorAll(".correct")[1].textContent = numberCorrect;
document.querySelectorAll(".incorrect")[1].textContent = numberWrong;
// If got perfect
if (perc === 100) {
document.querySelector(".continue").textContent = "Start Over?";
document.querySelector(".continue").addEventListener('click', function(){
document.querySelector(".correct").textContent = "";
app.flashcards.makeCards(app.flashcards.deckNum); // resets card values
cardTotal = 0;
app.results.hide();
app.flashcards.show();
});
} else { // otherwise
document.querySelector(".continue").textContent = "Continue";
document.querySelector(".continue").addEventListener('click', function(){
let tempKeys = [];
let tempValues = [];
document.querySelector(".incorrect").textContent = "";
for (let i = 0; i < wrongCards.length; i ++) {
tempKeys.push(wrongCards[i][0]);
tempValues.push(wrongCards[i][1]);
}
app.flashcards.cardValues = [tempKeys, tempValues];
cardTotal = 0;
app.results.hide();
app.flashcards.show();
});
}
}
hide() {
this.containerElement.classList.add('inactive');
}
}