首页 > 解决方案 > 来自 json 的测验脚本

问题描述

我正在制作一个测验脚本来学习 javascript。我有一个包含测验问题和答案的 json 文件

例子:

"quiz": [
{
  id:"0";
  question: "Who is the strongest?",
  answers: [
   {"name":"btn1","next_question":"1"},
   {"name":"btn2","next_question":"2"},]
   },
 },
{
  id:"1";
  question: "What is the best site ever created?",
  answers: [{
    {"name":"btn1","next_question":"0"},
    {"name":"btn2","next_question":"2"},]
  },
},
{
  id:"2";
  question: "Where is Waldo really?",
  answers: {
    {"name":"btn1","next_question":"1"},
    {"name":"btn2","next_question":"2"},
  },
}];}

因此,我需要始终从 id (0) 的问题开始进行测验。next_question 字段显示下一个问题将是什么。我怎样才能使这成为可能?谁能帮我解决这个问题?

有点类似的测验(https://github.com/evgeniikucheriavii/JS-quizes

标签: javascriptarraysjson

解决方案


推荐阅读