计算Javascript游戏的错误答案

计算Javascript游戏的错误答案,javascript,for-loop,Javascript,For Loop,因此,我试图为我的地理课制作一个javascript游戏,但我遇到了一些麻烦,我可以问问题并告诉你你是否错了,但我希望能够跟踪错误的答案。我想跟踪使用进行循环,但我不擅长,希望能得到一些帮助 这是每个问题的基础,只是&&是我需要在不正确的计数中添加一个标记的地方,我确信我需要使用进行循环 var y = "You are correct!!!" var n = "You are incorrect!!!" alert("Chapter 1, Human Cultural Connections

因此,我试图为我的地理课制作一个javascript游戏,但我遇到了一些麻烦,我可以问问题并告诉你你是否错了,但我希望能够跟踪错误的答案。我想跟踪使用
进行
循环,但我不擅长,希望能得到一些帮助

这是每个问题的基础,只是&&是我需要在不正确的计数中添加一个标记的地方,我确信我需要使用
进行循环

var y = "You are correct!!!"
var n = "You are incorrect!!!"

alert("Chapter 1, Human Cultural Connections. 1-10")
//==================================================
var Q1 = prompt("Demographers identify three different stages of life. 
They are children, working adults, and older adults. What is the age 
range for children? 0-13, 0-15, 0-18")

if (Q1 === "0-13")
{
alert(y)
}
else
{
alert(n) //&& add 1 tally to incorrect list
}
如果有人能帮我,这将是非常有帮助的,不要担心这是过去做任何方式,但我仍然想知道如何做它为未来的项目


p、 我已经有了HTML脚本,所以我不需要帮助

添加变量以跟踪错误答案:

var y = "You are correct!!!"
var n = "You are incorrect!!!"
var incorrectCount = 0;

alert("Chapter 1, Human Cultural Connections. 1-10")
//==================================================
var Q1 = prompt("Demographers identify three different stages of life. 
They are children, working adults, and older adults. What is the age 
range for children? 0-13, 0-15, 0-18")

if (Q1 === "0-13")
{
alert(y)
}
else
{
alert(n) //&& add 1 tally to incorrect list
incorrectCount++;
}

我知道这实际上超出了您的要求,但它可能会为您提供更好的灵活性和关于js for循环如何工作的知识。希望能有所帮助。

可能会有所帮助。
var correctCount=0在顶部和
correctCount++
警报(y)
之后?我会尝试一下,看看happensIt是如何完美工作的,不,我需要做的只是找出当计数器达到5时如何终止游戏
var correct = [], // well store the index of the correctly answered questions here
    wrong = [], // well store the index of the incorrectly answered questions here
    questions = [
    {
        "question": "Demographers identify three different stages of life. They are children, working adults, and older adults. What is the age range for children?",
        "answers": ["0-13", "0-15", "0-18"],
        "correct": 0 // correct answer is item of index 0 in property "answers" (0-13)
    },
    {
        "question": "whats your favorite color?",
        "answers": ["red", "yellow", "blue", "purple"],
        "correct": 2 // blue
    }
];

for (var i in questions){
    var answer = prompt(questions[i].question + questions[i].answers.join(','));
    if (answer == questions[i].answers[questions[i].correct]){
        correct.push(i);
    }else{
        wrong.push(i);
    }    
}

alert('wrong number of answers: ' + wrong.length);
alert('correct number of answers: ' + correct.length);
alert('first wrong question: ' + questions[wrong[0]].question);