I would like to create a simple tally system to record the data-id from the elements that are selected and combine the data-id values at the end to generate a result.
function myAnswer() {
document.getElementById('btnNxt').removeAttribute('disabled');
var myResult = '';
var iId = this.getAttribute('data-id');
myObj[page].mySel = iId;
myQueRep[page] = iId;
console.log(iId);
for (var x = 0; x < btn.length; x++) {
if (iId == x) {
btn[x].classList.add('selAnswer');
} else {
btn[x].classList.remove('selAnswer');
}
}
}
In this section, the iId variable gets the data-id value but I'm not sure how to tally the selections up and display a result based on that score.
JSFiddle of current code:
Player.scoremight be as simple asreturn Quiz.score(Player.answers). I see these objects:Question,Quiz(a collection of questions),Player,Page(maybe). Questions may need unique IDs for easy referencing, answer checking, etc. That might get rid of the page counting.