2017-09-19 44 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(); 
    } 
    //... 
    }); 
})() 
相關問題