I want to make a math quiz. I have 3 questions and 3 arrays. I want to make more questions and arrays in loops.
Here is working fiddle:
https://jsfiddle.net/ysbxcqu8/
Here is my code with missing eval():
function getResults() {
const questionsCount = document.getElementsByClassName("questions").length;
var amountCorrect = 0;
let signArr = [];
var x = new Array(3);
for(var i = 0; i < questionsCount; i++) {
var radiosName = document.getElementsByName('answer' + (i + 1));
x[i] = [];
x[i].push( document.getElementsByClassName("first")[i].innerText );
x[i].push( document.getElementsByClassName("second")[i].innerText );
x[i].push( document.getElementsByClassName("resultSpan")[i].innerText );
for (var j = 0; j < radiosName.length; j++) {
if( i == 0 )
signArr.push(document.getElementsByClassName("sign")[j].nextSibling.innerText);
var radiosValue = radiosName[j];
if (radiosValue.checked) {
if ( eval( ) == )
{
radiosValue.value = "correct";
amountCorrect++;
console.log("ok");
}else{
console.log("wrong")
}
}
}
}
document.getElementById('results').innerHTML = "Correct answers: " + amountCorrect;
}
I don’t know how to write an if instruction with eval function. Could you help me, please?