function init() { var question = [ ["12×3", 6, 0, 3, 0, 36], ["26×2", 12, 1, 4, 0, 52], ["43×3", 9, 0, 12, 1, 129], ["65×5", 25, 2, 32, 3, 325], ["87×9", 63, 6, 78, 7, 783] ]; var j; var i = 0; function calc() { for (j = 1; j < 6; j++) { var anser = document.getElementById('q' + j).value; if (anser == question[i][j]) { document.getElementById('a' + j).innerHTML = "○"; } else { document.getElementById('a' + j).innerHTML = "×"; } } } function next_q() { document.anserform.reset(); for (j = 1; j < 6; j++) { document.getElementById('a' + j).innerHTML = ""; } i++; document.getElementById(question).textContent = question[i][0]; } var ans = document.getElementById('ans'); ans.addEventListener('click', calc); var next = document.getElementById('next'); next.addEventListener('click', next_q); } window.onload = init();