我已经实现了一个游戏应用程序,其中有四个选项,其中有一个答案。选项随机排列。如何检查所选选项是否正确答案?
答案 0 :(得分:0)
保留将问题索引或问题与答案相关联的NSArray
或NSDictionary
答案 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');
}
});