var problems = [{question:'1+1',options:['0','1','2'],answer:'2'}, {question:'12-3',options:['12','9','6'],answer:'9'}, {question:'5*6',options:['15','18','30'],answer:'30'}, {question:'124/4',options:['31','62','124'],answer:'31'}, {question:'15*5',options:['155','75','65'],answer:'75'}, {question:'183+37',options:['210','220','230'],answer:'220'}]; var n = 0; // The current problem number var correct = 0; // Function to display the current problem. function displayProblem() { $('#question').text(problems[n].question); $('#one').text(problems[n].options[0]); $('#two').text(problems[n].options[1]); $('#three').text(problems[n].options[2]); } // Clicking one of the answer buttons calls this function. function answer() { if($(this).text() == problems[n].answer) correct = correct+1; if(n < 5) { n = n + 1; displayProblem(); } else { $('#questions').hide(); $('#score').text(correct); $('#results').show(); } } function setUp() { $('#one').click(answer); $('#two').click(answer); $('#three').click(answer); displayProblem(); $('#results').hide(); } $(document).ready(setUp);