JavaScript单击按钮,并从数组中给出下一个问题和答案

时间:2018-12-03 23:15:49

标签: javascript arrays

如何使make array从第一个问题转到下一个问题?

我可以为答案做同样的事情吗?

谢谢!

var allQuestions = [
            {
              question: "Welk kerstnummer draai jij grijs tijdens de feestdagen?",
              responses: [{
                text: 'Feliz Navidad',
              }

        var currentQuestion = 0;

            function showQuestion() {
              question = allQuestions[currentQuestion].question;
              questions.innerHTML = "<p>" + question + "</p>";

              for (var i = 0; i < allQuestions[currentQuestion].responses.length; i++) {
                responses = allQuestions[currentQuestion].responses[i].text;
                quizForm.innerHTML += "<button id='button'>" + responses + "</button>";
              }

              $('#choiceList').on('click', function() {

                if (currentQuestion < allQuestions.length - 1) {
                  currentQuestion++;
                } else {
                  alert('einde quiz')
                  return false;
                }

                document.getElementById("question").innerHTML = allQuestions[questions];

              });

            }

0 个答案:

没有答案