Skip to content

Commit

Permalink
Replace string literals on template with file read
Browse files Browse the repository at this point in the history
This fixes a bug introduced by a mismatch between the string literals
on template.py and back.html.
  • Loading branch information
3ter committed Oct 29, 2022
1 parent d02eb72 commit 32b4407
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 512 deletions.
11 changes: 4 additions & 7 deletions card/back.html → src/multiple_choice/card/back.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,9 @@
// Check if Persistence is recognized to prevent errors when viewing note in "Manage Note Types..."
if (Persistence.isAvailable && Persistence.getItem('Q_solutions') !== null) {
// Parsing solutions
console.log(Persistence.getItem('Q_solutions'));
var solutions = Persistence.getItem('Q_solutions').split(" ");
for (let i = 0; i < solutions.length; i++) {
solutions[i] = Number(solutions[i]);
}
var solutions = Persistence.getItem('Q_solutions');
var answers = Persistence.getItem('user_answers');

var type = document.getElementById('CardType').innerHTML;
var qtable = document.getElementById('qtable');
qtable.innerHTML = Persistence.getItem('qtable');
Expand All @@ -78,10 +75,10 @@
if (solutions[i] && answers[i] === 1) {
qrows[(type != 0) ? i : i + 1].setAttribute("class", options.qtable.colors.correctcorrect);
} else if (!solutions[i] && answers[i] === 0) {
qrows[(type != 0) ? i : i + 1].setAttribute("class", options.qtable.colors.wrongwrong);
qrows[(type != 0) ? i : i + 1].setAttribute("class", options.qtable.colors.wrongwrong);
} else if (!solutions[i] && answers[i] === 1) {
qrows[(type != 0) ? i : i + 1].setAttribute("class", options.qtable.colors.wrongcorrect);
} else if (solutions[i] && answers[i] === 0){
} else if (solutions[i] && answers[i] === 0) {
qrows[(type != 0) ? i : i + 1].setAttribute("class", options.qtable.colors.correctwrong);
} else if (type == 0 && answers[i] === 2) {
qrows[(type != 0) ? i : i + 1].setAttribute("class", options.qtable.colors.eithernone);
Expand Down
File renamed without changes.
8 changes: 7 additions & 1 deletion card/front.html → src/multiple_choice/card/front.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@
return userAnswers
}

function getCorrectAnswers() {
let solutions = document.getElementById("Q_solutions").innerHTML.split(" ").map(string => Number(string));

return solutions;
}

/**
* On checking an option this collects and stores answers in between front/back of the card.
*
Expand All @@ -175,7 +181,7 @@
if (Persistence.isAvailable()) {
Persistence.clear();
Persistence.setItem('user_answers', getUserAnswers());
Persistence.setItem('Q_solutions', document.getElementById("Q_solutions").innerHTML);
Persistence.setItem('Q_solutions', getCorrectAnswers());
Persistence.setItem('qtable', document.getElementById("qtable").innerHTML);
}
}
Expand Down
Loading

0 comments on commit 32b4407

Please sign in to comment.