gpt4 book ai didi

javascript - 循环卡在第一个区间

转载 作者:行者123 更新时间:2023-11-30 09:30:50 24 4
gpt4 key购买 nike

我知道你们中的一些人很快就会发现这一点,但出于某种原因,当使用 onclick 命令点击按钮时,我无法让循​​环比初始循环循环更多。

//creat array with my questions
var qArray = [
'What is the answer to the sum 1 + 1?',
'If I have two eggs and I drop one how many do I have left?',
'What are the three primary colors?'
];

//create variables
var counter = 0;
var theQuestions = document.getElementById('theQuestions');

//loop through array
function questFunc() {
for (var i = 0; i < qArray.length; i++) {
theQuestions.innerHTML = qArray[i];
counter++;
}
};

如有任何帮助,我们将不胜感激。我环顾四周但找不到它,我确定这是因为它是一个如此明显的修复/愚蠢错误 :D

谢谢你..

最佳答案

如果你想在每次点击按钮时显示一个新问题。您可以尝试以下操作:

//creat array with my questions
var qArray = ['What is the answer to the sum 1 + 1?', 'If I have two eggs and I drop one how many do I have left?', 'What are the three primary colors?'];

//create variables
var counter = 0;
var theQuestions = document.getElementById('theQuestions');

//loop through array
function questFunc() {
if (counter < qArray.length) {
theQuestions.innerHTML = qArray[counter];
counter++;
}
};

关于javascript - 循环卡在第一个区间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46373534/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com