作者:张逸紫惟雨 | 来源:互联网 | 2023-02-04 06:53
ImtryingtousethequestionIDvariabletokeeptrackofsomequestionsandanswers.ButitseemsI
Im trying to use the questionID variable to keep track of some questions and answers. But it seems I have problem with that the variable lose its memory, for each time I run my function ? thats what I think anyway.
我试图使用questionID变量来跟踪一些问题和答案。但是,每次运行我的函数时,似乎我都有变量丢失内存的问题?这就是我的想法。
When i ask for: color, and then follow up with an answer of: pink, purple or green, it jumps to the last statement; else if(questiOnID== -1)
which is not my intention.
当我要求:颜色,然后跟进答案:粉红色,紫色或绿色,它跳到最后一个声明;否则if(questiOnID== -1)这不是我的意图。
How can I fix this behaviour ? I run the script locally.
我该如何解决这个问题?我在本地运行脚本。
var questiOnID= -1;
function askQ() {
var findme = document.getElementById('askBox').value.toLowerCase();
var dOntUnderstand= new Array();
dontUnderstand[0] = "Excuse me, What did You say ?";
dontUnderstand[1] = "Sorry, I cant understand You now. ^_^";
dontUnderstand[2] = "Sorry!, I got to go now... CU !";
dontUnderstand[3] = "ohh... Can you repeat that one more time ?";
var randomIndex = Math.round(Math.random() * 3);
if (findme.match(/(age|old)/)) {
document.getElementById('bubble').innerHTML = "ohh,, I am " +
obj1.age + " years old, How old are You ?";
}
if (!isNaN(findme)) {
document.getElementById('bubble').innerHTML = "ohh.. that's kinda old !";
}
if (findme.match(/(color)/)) {
document.getElementById('bubble').innerHTML = "My favourite color " +
" is Purple, What's yours ?";
questiOnID= 6;
}
if (findme.match(/(pink|purple|green)/) && questiOnID== 6) {
document.getElementById('bubble').innerHTML = "well...that's cute !!";
questiOnID= -1;
}
if (findme.match(/(hi|hello)/)) {
document.getElementById('bubble').innerHTML = "Hi there, nice to meet You !";
} else if (questiOnID== -1) {
document.getElementById('bubble').innerHTML = dontUnderstand[randomIndex];
}
}
2 个解决方案