var exercise= [
['What is the first name of our professor in this course?', 'cecilia'],
['What is the last name of our prof in this coursrs?', 'chan'],
['Which language is the most popular one in the world?', 'javascript']
];
var player_ans;
var correct_num=0;
for(var i=0; i<exercise.length; i++){
player_ans= prompt(exercise[i][0]);
if(player_ans.toLowerCase === exercise[i][1]){
correct_num+= 1;
}
}
document.write('The number of question you answered correctly is '+ correct_num);
在我正确回答所有问题后,我希望correct_num的值为3。但是,屏幕上显示的correct_num的值仍为0 ...非常感谢您的帮助。谢谢。
最佳答案
toLowerCase
是一个函数,因此将其用作toLowerCase()
var exercise= [
['What is the first name of our professor in this course?', 'cecilia'],
['What is the last name of our prof in this coursrs?', 'chan'],
['Which language is the most popular one in the world?', 'javascript']
];
var player_ans;
var correct_num=0;
for(var i=0; i<exercise.length; i++){
player_ans= prompt(exercise[i][0]);
if(player_ans.toLowerCase() === exercise[i][1])
{ correct_num+= 1;
console.log(player_ans)
}
}
document.write('The number of question you answered correctly is '+ correct_num);
关于javascript - 无法检测到二维数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56885529/