我从这个网站https://www.sitepoint.com/simple-javascript-quiz/借用了一个测验的代码,问题是,我试图让问题以随机顺序显示在屏幕上,而不是在每次都一样的顺序。我尝试了多种方法,但似乎都不起作用,因此非常感谢您的帮助。我猜解决方案在于这个函数,但我不完全确定要修改什么。
function buildQuiz() {
// we'll need a place to store the HTML output
const output = [];
// for each question...
myQuestions.forEach((currentQuestion, questionNumber) => {
// we'll want to store the list of answer choices
const answers = [];
// and for each available answer...
for (letter in currentQuestion.answers) {
// ...add an HTML radio button
answers.push(
`<label>
<input type="radio" name="question${questionNumber}" value="${letter}" id="botones">
${letter} :
${currentQuestion.answers[letter]}
</label>`
);
}
// add this question and its answers to the output
output.push(
`<div class="slide">
<div class="question"> ${currentQuestion.question} </div>
<div class="answers"> ${answers.join("")} </div>
</div>`
);
});
// finally combine our output list into one string of HTML and put it on the page quizContainer.innerHTML = output.join(""); }
ITMISS
侃侃尔雅
相关分类