2017-09-19 42 views
1

我要想起这我想调用readline。怎么做?

rl.question("input your port do you want (about 0 - 65535) : ", function(portnumber) 
在此之后

if(netinfo > 6665){ 
    return console.log("Error stupid i say about 0 - 65535") 
} 

rl.question("input your port do you want (about 0 - 65535) : ", function(portnumber){ 
    if(netinfo > 6665){ 
    return console.log("Error stupid i say about 0 - 65535") 
    } 

    netinfo = portnumber; 

    const requestHandler = (request, response) => { 
     console.log(request.url) 
     response.write('<b>welcome to groone simple http server :p </b>'); 
     response.end('ahahahahahah :)'); 
    } 

如何做到这一点?

回答

0

您需要一个无限循环,当我们收到正确的/预期的答案时会断开。

示例代码:

var correctAnswer = false; 
while(!correctAnswer){ 
    doStuff() 
    if(0 < receivedAnswer && receivedAnswer < 6665) correctAnswer = true; 
} 
1

我看到的唯一方法是递归:

(function restart(){ 
    rl.question("input your port do you want (about 0 - 65535) : ", function(portnumber){ 
    if(portnumber > 6665){ 
     console.log("Error stupid i say about 0 - 65535"); 
     return restart(); 
    } 
    //... 
    }); 
})() 
相关问题