单击提交后如何获得下一个问题

时间:2018-12-19 01:32:49

标签: javascript loops

我正在尝试提交第一个问题后继续提出问题。我还需要计算分数。挂了电话,寻找我可以得到的任何帮助

  let questions = [
  {
  question : "how many stages are in the tour de france?",
  options : [
    {
    option : "2"
  },
  { 
    option : "10"
  },
  {
    option : "15"
  },
  { 
    option : "21"
  }
],
answer : "D"
},
{
question : "how many guys are on each team?",
options : [
  {
    option :"9"
  },
  { 
    option : "10"
  },
  {
    option : "8"
  },
  { 
    option : "7"
  }
 ],
  answer : "A"
 },
  {
 question : "how many times did Lance Armstrong win the tour?",
options : [
  {
    option :"7"
  },
  { 
    option : "4"
  },
  {
    option : "2"
  },
  { 
    option : "9"
  }
  ],
  answer : "A"
  },
  {
 question : "who won in 2018?",
options : [
  {
    option :"Garrent Thomas"
  },
  { 
    option : "Chris Froome"
  },
  {
    option : "Peter Sagan"
  },
  { 
    option : "Taylor Phinney"
  }
],
  answer : "A"
 },
 {
 question : "what team won the tour in 2017",
options : [
  {
    option :"Movistar"
  },
  { 
    option : "Bora"
  },
  {
    option : "sky"
  },
  { 
    option : "dropac"
  }
 ],
  answer : "c"
  },
 ];

我知道我需要对下面的这两个让做点事情

让currentQuestion = 0;    console.log(currentQuestion);

让得分= 0;

函数renderQuestion(){

  return `
  <fieldset>
    <legend> ${questions[currentQuestion].question} </legend>
    <input type="radio" name="option" 
 value="A">${questions[currentQuestion].options[0].option}<br>
    <input type="radio" name="option" 
 value="B">${questions[currentQuestion].options[1].option}<br>
    <input type="radio" name="option" 
value="C">${questions[currentQuestion].options[2].option}<br>
    <input type="radio" name="option" 
value="D">${questions[currentQuestion].options[3].option}<br>
    <button type="submit" class="submitAnswer"> Submit answer </button>
   </fieldset>

`;
 }

 function startQuiz(){
  $('.quizAppForm').on('click', '.startQuiz', function(event){
event.preventDefault();

$('.quizAppForm').html(renderQuestion);
});

}
function init(){
  startQuiz();

}

$(init);

0 个答案:

没有答案