如果用户写入“文本”超过两次,则会弹出错误

时间:2013-11-05 12:41:02

标签: ajax node.js

if (question == "What is the market?") {
    post = "You can find it @ " + store.market + ".";
    response.sendfile("src/index.html");
}

我有一个输入文本框,当用户写名字时?电脑说:“我的名字是(me.name)。

此代码位于 server.js

但我想做什么..如果用户写名字?喜欢3次左右。它会出现一个错误,上面写着你曾经多次问我这个问题。

我试着用(var i = 0; i< 3; ++ i) textbox =“错误” 但是我无法让它发挥作用。我不是最好的程序员,但我正在尝试。可以通过简单的循环完成,还是需要更多的东西?

1 个答案:

答案 0 :(得分:1)

试试这个:

var n=0, a=0, d=0;
if (question == "Name?") {
    if(n<3)
        answ = "I am " + me.name + ".";
    else
        answ = "You asked me that " + n + " times.";
    response.sendfile("public/index.html");
    n++;
} else if (question == "Age?") {
    if(a<3)
        answ = "I am " + me.age + " years old.";
    else
        answ = "You asked me that " + a + " times.";
    response.sendfile("public/index.html");
    a++;
} else if (question == "Do you have a name?") {
    if(d<3)
        answ = "My name is:" + me.Name";
    else
        answ = "You've asked me that " + d + " times.";
    response.sendfile("public/index.html");
    d++;
}

基本上,您会在and跟踪他们提出问题的次数,并相应地更改您的回复。