如何使用Javascript从列表中选择元素。以下是我的一些代码:
var score = 0;
var bin = 0;
var question = -1;
var answers = ['higher', 'lower', 'higher', 'lower', 'higher'];
function answer_question(response) {
if (response == 1) {
if (answer[question] == "higher"){
score ++;
console.log(score);
} else {
bin ++;
console.log("Bin: ");
console.log(bin);
}
}
else if (response == 0) {
if (answer[question] == "lower") {
score ++;
console.log(score);
} else {
bin ++;
console.log("Bin: ");
console.log(bin);
}
}
}
然而,它不起作用,我认为这是由于
answer[question] == "higher"
感谢您的帮助!