';
q.options.forEach(function(opt, i) {
var cls = 'quiz-option';
if (s.answered) {
if (i === q.correct_index) cls += ' correct';
else if (i === s.selected) cls += ' wrong';
} else if (i === s.selected) cls += ' selected';
h += '';
});
h += '
';
if (s.answered) {
h += '
Erklaerung
' + Markdown.render(q.full_answer) + '
';
h += '';
}
h += '
';
el.innerHTML = h;
var self = this;
if (!s.answered) {
el.querySelectorAll('.quiz-option').forEach(function(btn) {
btn.addEventListener('click', function() { self.selectOption(parseInt(btn.dataset.idx)); });
});
} else {
document.getElementById('quiz-next').addEventListener('click', function() { self.next(); });
}
},
selectOption: function(index) {
var s = this.state;
if (s.answered) return;
s.selected = index;
if (index === s.questions[s.index].correct_index) s.correct++;
s.answered = true;
this.renderQuestion(document.getElementById('content'));
},
next: function() {
this.state.index++;
this.state.selected = -1;
this.state.answered = false;
this.renderQuestion(document.getElementById('content'));
},
renderResult: function(el) {
var s = this.state;
var total = s.questions.length;
var pct = Math.round((s.correct / total) * 100);
API.post('/quiz/submit', { deck: s.deck, total: total, correct: s.correct }).catch(function() {});
var color = pct >= 70 ? 'var(--green)' : pct >= 40 ? 'var(--orange)' : 'var(--red)';
var h = '