如何在游戏应用中匹配正确的答案和问题

时间:2009-12-09 07:59:14

标签: node.js json nosql backend

我已经实现了一个游戏应用程序,其中有四个选项,其中有一个答案。选项随机排列。如何检查所选选项是否正确答案?

2 个答案:

答案 0 :(得分:0)

保留将问题索引或问题与答案相关联的NSArrayNSDictionary

答案 1 :(得分:0)

这行得通,

const quiz = [
    {
        question: 'this is a question',
        answer: 'the answer',
        choices: []
    }
];

quiz.forEach(item => {
    console.log(item.question);
    
    // im hardcoding the selected answer as an example be sure to dynamically populate this with the users input

    let selectedAnswer = 'the answer';
    if (selectedAnswer === item.answer) {
        console.log('correct answer');
    } else {
        console.log('incorrect answer');
    }
});