I am trying to create a loop where I can keep prompting myself question while not exiting the loop until I enter 1. however it is not working at the moment, any advise?
var prompt = require('prompt'); //require to use prompt
var sync = require('sync'); //require to use synchronous function
var choice = 0;
sync(function()
{
while(choice != 1)
{
if(choice == 0)
{
prompt.start();
prompt.get(['message'], function(err, result)
{
if (err)
{
return onErr(err);
}
data(result.message);
choice = result.message;
});
}
else if (choice == 1)
{
break;
}
}
});
prompt.get()never has a chance to run because thewhileis blocking the job queue. Learn about run to completion: developer.mozilla.org/en-US/docs/Web/JavaScript/… .var result = prompt.get.sync(['message']).