# 如何循环提问How to loop through questions

HTML：

``````<form>
<tr>
<td>&nbsp;</td>
<td colspan="1" align="right"><input id="carryOver"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="2" align="right" id="firstNum">48</td>
</tr>
<tr>
<td>+</td>
<td colspan="2" align="right" id="secondNum">16</td>
</tr>
<tr>
<td colspan="3"><hr id="sepLine"></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
</tr>
</table>
</form>
``````

JavaScript：

``````var numOne = [48,39,16,43,37,23,44,13,37,28,48,16];    // first number in addition problem
var numTwo = [16,22,25,18,46,49,18,39,25,17,9,28];     // second number in addition problem

var i = 0;

// assigns guessed number to variable

if (guess == numOne[i]+numTwo[i]) {
if(confirm("Correct!")) {
// next question
i++;
document.getElementById('firstNum').innerHTML=numOne[i];
document.getElementById('secondNum').innerHTML=numTwo[i];
}
} else {
if(confirm("Incorrect")) {
// next question
i++;
document.getElementById('firstNum').innerHTML=numOne[i];
document.getElementById('secondNum').innerHTML=numTwo[i];
}
}
}
``````

## 2 个回复2

### ===============>>#1 票数：0 已采纳

getElementById将字符串作为参数，因此您需要这样做：

``````document.getElementById('numOne').innerHTML=numOne[i]; //notice the single quotes around numOne
``````

### ===============>>#2 票数：0

``````    var numOne = [48, 39, 16, 43, 37, 23, 44, 13, 37, 28, 48, 16];
var numTwo = [16, 22, 25, 18, 46, 49, 18, 39, 25, 17, 9, 28];
var i = 0;

a = document.getElementById('firstNum').innerHTML = numOne[i];
b = document.getElementById('secondNum').innerHTML = numTwo[i];
i++;
}
function clicked() {
var c = a + b;
if (guess == c) {
}
else {
}
a = document.getElementById('firstNum').innerHTML = numOne[i];
b = document.getElementById('secondNum').innerHTML = numTwo[i];
i++;
}

<form>
<tr>
<td></td>
<td colspan="2" align="right" id="firstNum"></td>
</tr>
<tr>
<td>+</td>
<td colspan="2" align="right" id="secondNum"></td>
</tr>
<tr>
<td colspan="3">
<hr id="sepLine">
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="2" align="right">
</td>
</tr>
<tr>
<td colspan="3">
<input type="button" onclick="clicked();" value="Submit"/>
</td>
</tr>
</table>
</form>
``````

``````    //var numOne = [48, 39, 16, 43, 37, 23, 44, 13, 37, 28, 48, 16];
//var numTwo = [16, 22, 25, 18, 46, 49, 18, 39, 25, 17, 9, 28];
score = 0;
var md = [
[48, 16],
[39, 22],
[16, 25],
[43, 18],
[37, 46],
[23, 49],
[44, 18],
[13, 39],
[37, 25],
[28, 17],
[48, 9],
[16, 28],
];
var i = 0;
var j = 1;
var z = 0;
a = document.getElementById('firstNum').innerHTML = md[i][i];
b = document.getElementById('secondNum').innerHTML = md[i][j];
i++;
}
function clicked() {
var c = a + b;
if (guess == c) {