第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

不應(yīng)發(fā)生嵌套對(duì)象語(yǔ)法錯(cuò)誤

不應(yīng)發(fā)生嵌套對(duì)象語(yǔ)法錯(cuò)誤

BIG陽(yáng) 2021-04-06 17:13:43
我遇到了一個(gè)“語(yǔ)法錯(cuò)誤”,這確實(shí)很煩人,在嘗試修復(fù)它時(shí),我嘗試使用可怕的語(yǔ)法,因?yàn)檫@基本上就是該錯(cuò)誤所說(shuō)的。該錯(cuò)誤說(shuō):SyntaxError: missing } after property list[Learn More] questions.js:11:1note: { opened at line 1, column 19這不應(yīng)該發(fā)生,因?yàn)槲乙呀?jīng)關(guān)閉了所有括號(hào),并為嵌套對(duì)象使用了完美的JavaScript語(yǔ)法。let allQuestions = {    question1: {        question: 'You should ______ if a large animal is in your path and you cant stop in time.',        ans1: 'Brake hard',        ans2: 'Hit the animal at an angle',        ans3: 'Take your foot of the brakes so it doesnt go through your windshield',        ans4c: 'All of the above'    };    question2: {        question: 'How come motorcyclists often ride in the left part of the lane?',        ans1: 'They can pass cyclists on the right part of the lane'    };};
查看完整描述

2 回答

?
手掌心

TA貢獻(xiàn)1942條經(jīng)驗(yàn) 獲得超3個(gè)贊

只是語(yǔ)法錯(cuò)誤。每個(gè)嵌套對(duì)象后面的分號(hào)應(yīng)該只是逗號(hào)??矗?/p>


let allQuestions = {

    question1: {

        question: 'You should ______ if a large animal is in your path and you cant stop in time.',

        ans1: 'Brake hard',

        ans2: 'Hit the animal at an angle',

        ans3: 'Take your foot of the brakes so it doesnt go through your windshield',

        ans4c: 'All of the above'

    },

    question2: {

        question: 'How come motorcyclists often ride in the left part of the lane?',

        ans1: 'They can pass cyclists on the right part of the lane'

    }, //(optional comma here)


};


查看完整回答
反對(duì) 回復(fù) 2021-04-08
?
aluckdog

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超7個(gè)贊

這里已更正。


let allQuestions = {

    question1: {

        question: 'You should ______ if a large animal is in your path and you cant stop in time.',

        ans1: 'Brake hard',

        ans2: 'Hit the animal at an angle',

        ans3: 'Take your foot of the brakes so it doesnt go through your windshield',

        ans4c: 'All of the above'

    },

    question2: {

        question: 'How come motorcyclists often ride in the left part of the lane?',

        ans1: 'They can pass cyclists on the right part of the lane'

    }


};


console.log(allQuestions);

但是您是否考慮過(guò)結(jié)構(gòu)本身,使用數(shù)組,以便可以更輕松地迭代代碼。


let allQuestions = [{

    question: 'You should ______ if a large animal is in your path and you cant stop in time.',

    answers: [{

        id: 1,

        answer: 'Brake hard'

      },

      {

        id: 2,

        answer: 'Hit the animal at an angle'

      },

      {

        id: 3,

        answer: 'Take your foot of the brakes so it doesnt go through your windshield'

      },

      {

        id: 4,

        answer: 'All of the above'

      }

    ]

  },

  {

    question: 'How come motorcyclists often ride in the left part of the lane?',

    answers: [{

      id: 1,

      answer: 'They can pass cyclists on the right part of the lane'

    }]

  }

];


console.log(allQuestions);

因此,現(xiàn)在使用數(shù)組,我們可以輕松構(gòu)建HTML


let allQuestions = [{

    question: 'You should ______ if a large animal is in your path and you cant stop in time.',

    answers: [{

        id: 1,

        answer: 'Brake hard'

      },

      {

        id: 2,

        answer: 'Hit the animal at an angle'

      },

      {

        id: 3,

        answer: 'Take your foot of the brakes so it doesnt go through your windshield'

      },

      {

        id: 4,

        answer: 'All of the above'

      }

    ]

  },

  {

    question: 'How come motorcyclists often ride in the left part of the lane?',

    answers: [{

      id: 1,

      answer: 'They can pass cyclists on the right part of the lane'

    }]

  }

];


const getAnswerHtml = (answers) => answers.map(a => `<li id="${a.id}">${a.answer}</li>`).join('');

const getQuestionHtml = (question) => `<div class="question"><h3>${question.question}</h3><ul>${getAnswerHtml(question.answers)}</ul></div>`;


document.querySelector('.questions').innerHTML = allQuestions.map(q => getQuestionHtml(q)).join('');

<div class="questions"></div>


查看完整回答
反對(duì) 回復(fù) 2021-04-08
  • 2 回答
  • 0 關(guān)注
  • 230 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)