好的,所以我在搞乱数组,现在我正在尝试回答第二个问题,以提出新消息而不是“正确!” 当在这种情况下发现它正确时,如果第二个问题正确,我希望它回复“gerp”。但我不完全确定该怎么做。我在搞砸什么?
var i = 0;
var myArray = new Array({
q: "What was her favorite Color?",
a: "purple"
}, {
q: "gymhoaccetpptfe",
a: "rev six nine eleven"
});
function myFunction() {
var x;
var name = prompt(myArray[i].q);
if (name == myArray[i].a) {
x = document.getElementById("demo").innerHTML + " " + "correct!";
i = i + 1;
document.getElementById("demo").innerHTML = x;
} else if ((name == myArray[i + 1].a) {
x = document.getElementById("demo").innerHTML + " " + "gerp!";
} else {
x = document.getElementById("demo").innerHTML + name + " " + "is" + " " + "wrong!";
document.getElementById("demo").innerHTML = x;
}
}