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

我有一个输入文本框,当用户输入名称时?计算机显示“我的名字是 (me.name)。

此代码在server.js中

但我想做什么.. 如果用户写姓名?像3次左右。它会出现一个错误,说你已经问过我很多次或以这种方式。

我尝试使用 for (var i=0;i < 3; ++i) textbox = "Error" 但我无法让它工作。我不是最好的程序员,但我正在努力。可以用一个简单的循环来完成还是我需要更多的东西?

4

1 回答 1

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++;
}

a基本上,您会在、n、 以及他们提出问题的次数中进行跟踪d,并相应地更改您的回答。

于 2013-11-05T15:42:14.223 回答