javascript - How do you set a variable to the value returned from prompt('...')? -


In the code below, when I set the user variable in the indicated user input, the user adds the input variable. I know this because the value console The variable in the log statement appears right below the manifesto.

Though , the variables show the Door and Offer Door, which are set based on user input variables, work in a functionally manner that suggests that The variable did not "hold" the value. ( Vokski : It's easy to demonstrate than to understand. Please be run down code. UserDoor, different number appears, Door and offer fear in the range of 1-3. Let some time , Fear === user door. It should never happen.)

Interestingly, when I set the user door directly into an integer, this program works fine - see the commented debug line.

Why Does the user input variable show the correct value in the console but does not show up in the rest of the program?

(This program, which demonstrates the <

 < code> alert ( "there are three doors. death behind the two of them and another. behind a great fresh air"); var yWin = 0; var yLoss = 0; var nWin = 0; var nLoss = 0; while (True) {// noprotect var userDoor = prompt ("Select the door: 1, 2, or 3"); // var userDoor = 1 / debug design Ole.log ('UD:' + User); Var PrizeDur = Random Line (1,3); Console.log ('Pd:' + Reward Dure); Var Reveal = (function () {var Shows Dure = Prus Kar door; if (award Door === user Door) {while (reveal Door === Awards Door) {appears} Door = random range (1,3);} appears afraid;} else {while ( appear to be afraid === Awards Door || appear Door === Ughrdur) {Ptadh = Drent = Random range (1,3);} shows the returns Door;}}) (); Consoleklog ( ' RD: '+ revealing reverence); Var Offers Dure = (Function () {var Offer Door = Door Award; While (Offer Door === Disco Dances) Offers Drool === User Frustration} Door = randomRange (1,3);} Offer Door Change;}) (); Console.log ('OD:' + + Offer Door); Var like = prompt ( "You chose door" + UserDoor + "" door left rear + "appears + bad +", I reveal death and mind. I will give you a chance to change your choice "+ Offers Door +" Accept (y = n =);; if (like === "y") {userDoor = offerDoor;} Var result = (function () {var result; if (userDoor === reward door) { Warning ("You Receive Prizes!"); Results = 'W';} and {Warning ("You Sentenced to Death!"); Results = 'L';} Return Result;}); // Analytics: switch (result) {case 'w': if (likes === 'y') {yWin ++;} Else {nWin ++;} breakage; case 'L': if (like === 'Y') {yLoss ++;} Else {nLoss ++;} break;} Var done = prompt ("what are you doing? Y / n"); if (done === "y") {brake ;}} Function randomRange (minimum, maximum) {return Math.floor (Math.random () * (max - min + 1)) + 1;} var totalSamples = yWin + nWin + yLoss + nLoss; var yChoices = yWin + YLoss; var nChoices = nWin + nLoss; Console.log ('Total Samplets with a Sample Set); Console.log (' You chose to change '+ (yChoices / nChoices * 100) +' Time%. ') ; Console.log (When you choose to change 'when you', you 'win' (yWin / yChoices * 100) + '% of time.'); Console.log ('when you') has been chosen to live, you "win" (nWin / nChoices * 100) + 'time of%.');    
  var userDoor = sign (" Choose the door: 1,2, or 3 ")) * 1   

Its better use of 2 radio buttons

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -