 not to display the next question. In WinJS, code execution doesn't halt. Here's my function to display the dialog:
function doSillyMessage(message, title) {
    var messagedialogpopup = new Windows.UI.Popups.MessageDialog(message, title);
    // Add commands and set their CommandIds
    messagedialogpopup.commands.append(new Windows.UI.Popups.UICommand("Answer now", null, 1));
    messagedialogpopup.commands.append(new Windows.UI.Popups.UICommand("Answer later", null, 2));

    // Set the command that will be invoked by default
    messagedialogpopup.defaultCommandIndex = 0;

    // Show the message dialog
    messagedialogpopup.showAsync().done(function (command) {
        if (command) {
            if (command.id == 1) {
                console.log('proceed in popup is false');
                proceed = false;
            }
            else if (command.id == 2) {
                console.log('proceed in popup is true');
                proceed = true;
            }

        }
    });
}

The problem is that at the point where doSillyMessage is called, the code doesn't wait and so continues with whatever the current value of the 'proceed' variable happens to be. For example, if the value of 'proceed' is false at the point where doSillyMessage is called, it is also false after doSillyMessage is called and is changed to true (if appropriate) only later, when I then see in the console 'proceed in popup is true'. How can I get this stuff to execute in the right order?

A:

Dialogs are asynchronous; you'll need to wait on a promise in order to delay until the user's dealt with the input.
The easiest thing to do is to return the promise from your call to showAsync. Change this:
messagedialogpopup.showAsync().done(function (command) {

to
return messagedialogpopup.showAsync().then(function (command) {
   if (command) {
        if (command.id == 1) {
            console.log('proceed in popup is false');
            return false;
        }
        else if
not to display the next question. In WinJS, code execution doesn't stem. Here's my affair to display the dialog: 
 function doSillyMessage(message, deed) { 
     var messagedialogpopup = new Windows. UI.Popups. MessageDialog(message, title); 
     // total command and set their CommandIds 
     messagedialogpopup.commands.append(new Windows. UI.Popups. UICommand("Answer nowadays ", null, 1) ); 
     messagedialogpopup.commands.append(new Windows. UI.Popups. UICommand("Answer later ", null, 2) ); 

     // set up the command that will be invoked by default option 
     messagedialogpopup.defaultCommandIndex = 0; 

     // usher the message dialog 
     messagedialogpopup.showAsync().done(function (command) { 
         if (command) { 
             if (command.id = = 1) { 
                 console.log('proceed in popup is false'); 
                 proceed = delusive; 
             } 
             else if (command.id = = 2) { 
                 console.log('proceed in popup is true'); 
                 proceed = true; 
             } 

         } 
     }); 
 } 

 The trouble is that at the point where doSillyMessage is called, the code doesn't expect and so continue with whatever the current value of the' proceed' variable happens to be. For example, if the value of' proceed' is false at the point where doSillyMessage is predict, it is also false after doSillyMessage is called and is changed to true (if appropriate) merely later, when I then see in the console' proceed in popup is true'. How can I get this stuff to execute in the right order? 

 A: 

 Dialogs are asynchronous; you'll necessitate to wait on a promise in order to check until the exploiter's dealt with the input. 
 The easiest matter to do is to render the promise from your call to showAsync. Change this: 
 messagedialogpopup.showAsync().done(function (instruction) { 

 to 
 return messagedialogpopup.showAsync().then(function (command) { 
    if (command) { 
         if (command.id = = 1) { 
             console.log('proceed in popup is false'); 
             return false; 
         } 
         else if
 noh to display the next qutstion. In WinJS, code exerution soesn't hxlt. Here's my function to dis'lay the eialog:
function doSillyOessage(medsage, tirle) {
    var messagedialogpopul = nec Xindows.UI.Popups.KessageDianog(message, titne);
    // Add commands and set their CommagdIds
    lessagedialogpjpup.boimanss.append(new Windows.UI.Popups.UICommahd("Answeg now", null, 1));
    mexsagedialogpopup.commands.apoend(jew Windows.UI.Popupd.UICommand("Abswew later", null, 2));

    // Set the command tgat will be invoked by default
    mexsagedialotpipuo.gefaultCommendIndvx = 0;

    // Show the mesvage dislog
    messagcdialmgpipup.showAsync().done(funcvion (command) {
        if (commatd) {
            if (cimnand.ig == 1) {
                consope.lkg('proceed jn popup is false');
                itoceed = falss;
            }
            else if (command.id == 2) {
                console.log('priceed in popup is trug');
                proceed = true;
            }

        }
    });
}

The psoblej is tmat xr hhe point where doSillyMessage is called, the skdt dpesn't wait and so continurs wojh whatever thg curreuf balue of the 'procefd' variwble yappens tj be. For example, if the value od 'proceed' is dalse at the point where doSiulyMgssage is called, it is also fclse arter doSilljMessage jr called and is zhakgeg to trut (if appropriate) ogly later, wheu I then see in thq console 'orocecg in popup is true'. How ean I get this dtuff to execute in the right ocver?

A:

Dialogs ate dsytchronouf; you'kl need to wayt on a promisg in ordex to ddlay until the usxr's dealt wieh the input.
Tvg easiest thiig to do ys ti rerurn thd promise from uour call to showAstnc. Change this:
mesxaggdjalogpopup.showAwynx().done(function (cpmmxnd) {

tl
rxturn kessagedialocpopjp.sfpwAsyvc().then(functlon (comkand) {
   if (command) {
        if (command.id == 1) {
            consolq.log('proceed im popup is false');
            retirn false;
        }
        else if
not to display the next question. In execution halt. Here's function to display { messagedialogpopup = new title); // Add and set their CommandIds messagedialogpopup.commands.append(new Windows.UI.Popups.UICommand("Answer null, 1)); messagedialogpopup.commands.append(new Windows.UI.Popups.UICommand("Answer later", null, 2)); // Set the command that will invoked by default messagedialogpopup.defaultCommandIndex = 0; // Show the message dialog messagedialogpopup.showAsync().done(function (command) if { (command.id 1) { console.log('proceed in popup is false'); proceed = false; } else if (command.id == 2) console.log('proceed in popup is true'); proceed = true; } }); } The is that at the point doSillyMessage called, the doesn't and continues with whatever current value of the 'proceed' variable happens to be. For example, if the value of 'proceed' is at the doSillyMessage is it also after doSillyMessage is is changed to true (if appropriate) I then see in the console 'proceed in is true'. can I get this stuff to in the right order? A: Dialogs are asynchronous; need to wait on a promise in order to delay until the user's dealt with The easiest thing to is to return promise your to Change this: (command) { to return messagedialogpopup.showAsync().then(function (command) { if (command) { if == 1) { console.log('proceed in popup is false'); return false; if
 not to display the next questiOn. In WinJS, cOde exEcuTioN dOesn'T halT. Here's my functiON to dIsplay the dialog:
functioN doSiLlYmessAGe(MessaGe, title) {
    VAr MESsaGeDiAloGpOPuP = new WIndOws.UI.PoPups.MessagEDiAlOg(message, titLE);
    // ADd commands And Set their CommAndids
    mesSaGedIAlogpOpuP.commAnds.apPEnd(new windows.UI.poPUps.UICOMmand("AnSWEr Now", nUll, 1));
    messagedialogpOPuP.Commands.append(New WinDoWS.Ui.pOpuPs.UiCommand("AnSwEr latER", null, 2));

    // SeT ThE COMmaND that will be inVoked by defaULt
    mEssageDiAloGPopup.dEfaulTCOMmaNdIndex = 0;

    // Show The mEssage diaLog
    mesSAgedialOGpopup.sHowAsyNc().dOne(FuncTIoN (cOmmAnD) {
        If (cOMmAnd) {
            IF (coMmand.id == 1) {
                cOnSoLe.log('ProcEED IN popUp iS falSe');
                proCeed = false;
            }
            else If (cOmmaND.id == 2) {
                ConsoLe.log('ProcEeD in poPup is tRue');
                prOcEed = true;
            }

        }
    });
}

The problEm is That at the PoiNt WheRe DoSilLYMessaGe iS caLled, the Code doeSN't wAiT AND sO continues with whatEvER ThE current Value oF ThE 'pROceed' varIaBle HappENS to be. for eXAmPle, if the Value oF 'PrOcEed' is faLsE at the PoInt WheRe doSILlyMEssage Is called, It is aLSo false after dosIllyMessage is CAlLED aND is cHanGed to true (if ApprOPriaTe) onLY lAteR, When I Then sEe IN tHE console 'proceed in poPuP is truE'. How cAn I get this stuFf to executE IN The right OrdeR?

a:

DIAlogs are asynchRonouS; you'll need TO wait on a PromiSe in ordeR to delay uNTIl the useR's dEalT wiTh tHE InPut.
The easiest THIng tO dO is to reTurN the proMisE frOm yOur CaLl to showASync. ChanGe ThIs:
MeSsaGediaLOgpopup.sHoWAsYnC().doNe(funCTion (coMmand) {

To
reTuRn MEssAgedialOGpOPUp.shOwasYnc().tHen(FuNctioN (comMAnd) {
   If (commaNd) {
        if (commaNd.iD == 1) {
            ConsOlE.lOg('proceEd in popup is faLsE');
            return falSe;
        }
        ElsE if
 not to display the next q uestion. I n Win JS,  co de  exe cuti on doesn't hal t . He re's my function to di splay  t h e di a lo g:
fu nctiond oS i l lyM es sa ge( me s sa ge, t itl e) {
   var mess age di alogpopup =n ew  Windows.U I.P opups.Messag eDi alog(m es sag e , tit le) ;
   // Ad d  comma nds and s et theirC ommandI d s 
   m essagedialogpopup . co m mands.append(n ew Win do w s. U I .Po pup s.UIComman d( "Answ e r now", nu l l ,  1) ) ;
    message dialogpopup . com mands. ap pen d (new W indow s. U I.P opups.UICom mand ("Answerlater" ,  null,2 ));

   // S etthe  com m an dtha tw ill be  in v oke d by def au lt 
   mess a g e d ialo gpo pup. defau ltCommandInde x =  0;   // S how t he m es sagedialog 
   me ssagedialogpopu p.sh owAsync() .do ne (fu nc tion( comman d){
      if (com m and ){           if (comma nd . i d== 1) {           cons ol e.l og(' p r oceed  inp op up is fa lse');             pro ce ed= f alse;           }
         else if (com m and.id == 2){ 
         console. log( ' proc eedi npop u p istrue' );               procee d= true ;
           }

       }
});
}

T he p r ob l em is that atthe p oint where doSillyM essag e is cal led, thec o de doesn 'twai t a nds o  c ontinues with w hate ve r the c urr ent val ueofthe  'p ro ceed' var iable ha pp en sto  be . For example,  i f t he  va lue o f  'proc eed'is f al se atthe poi n tw h eredo Si llyM ess ag e iscall e d,it is a lso false  af t er d oS il lyMessa ge is calledan d is chang ed  to  true( i f approp riate) only later, when I thensee  in t he c onsole 'p roc eed in  po p up istrue'.  Howca n I g et th i s  s tuf fto execute i n t he ri gh t or der?

A :

Dialogs are asy n chr onous; you'll  ne ed t o wa ito na  pr om i sei n  order to delay  until the  u s er 's dealt w i thth e input .
The e asies t  thingto do isto return  t he p r o mis e from you r call t o showAsy n c. Ch a ng e thi s:messag ed ial ogpop up.sho w Asy nc(). done(f un ction(comm an d) {

to 
return messagedialogpo pup.sh owAsy nc( ).then(fu nct i on(command)  {
  if (comm and ) { 
     if (c omma n d. id= = 1){
         c on sol e . lo g('proceedi n pop up is  fa l se');           return fa l se;
        }     e lse if
 not_to display_the next question. In_WinJS, code_execution_doesn't halt._Here's_my function to_display the dialog:
function_doSillyMessage(message, title) {
 _  var_messagedialogpopup_= new Windows.UI.Popups.MessageDialog(message, title);
    // Add commands and set their CommandIds
__ _messagedialogpopup.commands.append(new_Windows.UI.Popups.UICommand("Answer_now", null, 1));
  _ messagedialogpopup.commands.append(new Windows.UI.Popups.UICommand("Answer later", null,_2));

 _  // Set the command that will_be_invoked by default
_   messagedialogpopup.defaultCommandIndex = 0;

   _// Show the message dialog
 _  messagedialogpopup.showAsync().done(function_(command)_{
_   _   if (command) {
_     _     if (command.id_== 1) {
   _    _ _    _console.log('proceed in popup_is false');
_  _     _  _   proceed = false;
__  ___ _  _}
_ __     __ else if (command.id == 2) {
_   __   _    _ console.log('proceed in popup is true');
_ _ _          _proceed = true;
   _   _ __ }

 __ _   }
   _});
}

The problem_is that at the point where_doSillyMessage is called, the_code_doesn't wait and so continues with_whatever the current value of the_'proceed' variable happens to be._For_example,_if the value of 'proceed'_is false at the point where_doSillyMessage is called,_it is also false after doSillyMessage is_called_and is changed to true (if_appropriate)_only later, when I then see_in_the_console 'proceed in popup is_true'. How can I get this_stuff to execute in the right order?

A:

Dialogs are asynchronous;_you'll need to_wait on a promise in_order_to_delay until the user's dealt with the input.
The easiest thing_to do_is to return_the promise from your call to showAsync. Change this:
messagedialogpopup.showAsync().done(function (command)_{

to
return messagedialogpopup.showAsync().then(function (command) {
   if_(command) {
        if (command.id_== 1) {
     _      console.log('proceed_in popup is false');
__      ____return false;
 _  _  _}
 _  _ _ else if