Javascript var问题右侧未添加正确答案

Javascript var问题右侧未添加正确答案,javascript,variables,Javascript,Variables,程序未在页面底部添加正确答案。我不知道为什么,即使chrome上的提示用大写字母正确回答,条件语句也没有将它们添加到问题右侧 var quiz = [ ['What is the capital of New York', 'Albany'], ['What is the Capital of California', 'Sacramento'], ['What is the capital of New Jersey', 'Trenton'], ['What

程序未在页面底部添加正确答案。我不知道为什么,即使chrome上的提示用大写字母正确回答,条件语句也没有将它们添加到问题右侧

 var quiz = [
    ['What is the capital of New York', 'Albany'],
    ['What is the Capital of California', 'Sacramento'],
    ['What is the capital of New Jersey', 'Trenton'],
    ['What is the capital of Virginia', 'Richmond']
];

var questionsRight = 0;
var questionsWrong = 0;
var questionsRightList = [];
var questionsWrongList = [];

/* Don't NEED to declare the following right away, but it's good practice to go ahead
and declare the variables you're going to use. Notice you don't need to assign any
default value to them */
var question;
var answer;
var response;
var html;

function print(message) {
  document.write(message);
}


    for( var i = 0; i < quiz.length; i++) {
        // Get the first item from array[i] and set it as question
        question = quiz[i][0];

          // Get the second item from array[i] and set it as answer
        answer = quiz[i][1];

        // Get input from the user and set it to the response variable
        response = prompt(question);

        if (question === answer) {
            //questionsRight is initially 0. If response === answer               questionsRight = 0+1
            questionsRight += 1;    
        }
        // else {
        //  //questionsWrong is initially 0. If response === answer questionsWrong = 0+1
        //  questionsWrong += 1;

        // }
    } 

    html = "You got " +  questionsRight + " question(s) right.";

    print(html);
var测验=[
[“纽约的首都是什么”,“奥尔巴尼”],
[“加利福尼亚州的首都是什么”,“萨克拉门托”],
[“新泽西州的首都是什么”,“特伦顿”],
[“弗吉尼亚州的首府是什么”,“里士满”]
];
var问题右=0;
var=0;
var questionsRightList=[];
var问题SWRONGLIST=[];
/*不需要立即声明以下内容,但继续进行是一种良好的做法
并声明要使用的变量。请注意,您不需要指定任何
它们的默认值*/
var问题;
var回答;
var反应;
var-html;
功能打印(消息){
文件。书写(信息);
}
对于(变量i=0;i
因为您正在比较(问题===答案)。这应该是(回答===答案)。

条件没有使用正确的左赋值

演示:

var测验=[
[“纽约的首都是什么”,“奥尔巴尼”],
[“加利福尼亚州的首都是什么”,“萨克拉门托”],
[“新泽西州的首都是什么”,“特伦顿”],
[“弗吉尼亚州的首府是什么”,“里士满”]
];
var问题右=0;
var=0;
var questionsRightList=[];
var问题SWRONGLIST=[];
/*不需要立即声明以下内容,但继续进行是一种良好的做法
并声明要使用的变量。请注意,您不需要指定任何
它们的默认值*/
var问题;
var回答;
var反应;
var-html;
功能打印(消息){
文件。书写(信息);
}
对于(变量i=0;i
Hello如果我们帮助您,请选择一个答案。
 var quiz = [
    ['What is the capital of New York', 'Albany'],
    ['What is the Capital of California', 'Sacramento'],
    ['What is the capital of New Jersey', 'Trenton'],
    ['What is the capital of Virginia', 'Richmond']
];

var questionsRight = 0;
var questionsWrong = 0;
var questionsRightList = [];
var questionsWrongList = [];

/* Don't NEED to declare the following right away, but it's good practice to go ahead
and declare the variables you're going to use. Notice you don't need to assign any
default value to them */
var question;
var answer;
var response;
var html;

function print(message) {
  document.write(message);
}


    for( var i = 0; i < quiz.length; i++) {
        // Get the first item from array[i] and set it as question
        question = quiz[i][0];

          // Get the second item from array[i] and set it as answer
        answer = quiz[i][1];

        // Get input from the user and set it to the response variable
        response = prompt(question);

        if (response.toLowerCase() === answer.toLowerCase()) {
            //questionsRight is initially 0. If response === answer               questionsRight = 0+1
            questionsRight += 1;    
        }
        // else {
        //  //questionsWrong is initially 0. If response === answer questionsWrong = 0+1
        //  questionsWrong += 1;

        // }
    } 

    html = "You got " +  questionsRight + " question(s) right.";

    print(html);