-1

I am working on a simple code, without getting into full detail, I'll jump straight to brass tacks.

Here is the simple code snippet that has a do-while construct repeat until the input is not a NaN.

do {
  var choice = parseInt(prompt("Please select one of the following:\n1.ROCK\n2.PAPER\n3.SCISSORS\n[NOTE: Choose your selection by pressing a number between 1,2 or 3.]"));
} while (isNaN(choice));

This code essentially prompts the user until a user's input meets while loop exit criteria. The code works fine if I execute in a chrome snippet. Although, the same code on jsbin does not prompt even if I enter a string input. I am curious whether is it something with the code or the website?

Below is screenshot proof for the same:

Chrome Snippet

Chrome Snippet execution

jsbin.com

js-bin-execution

mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • Works here too... – mplungjan Jul 03 '21 at 11:14
  • 4
    add `// noprotect` at the top of the js file. Jsbin doesn't executes your code like you expect it to because it is trying to protect you from potential infinite loop. – Yousaf Jul 03 '21 at 11:18
  • 1
    yes i am. Just add the `// noprotect` comment at the top of your js code. – Yousaf Jul 03 '21 at 11:20
  • With your code and without the `// noprotect` comment, you will see a warning message in the browser dev tool console telling you to add the `// noprotect` comment. – Yousaf Jul 03 '21 at 11:21
  • Does this answer your question? [Why does do-while not evaluate logical &&?](https://stackoverflow.com/questions/68235981/why-does-do-while-not-evaluate-logical) – Nick.Mc Nov 12 '21 at 03:20

1 Answers1

1

All thanks to @Yousaf, I was able to figure out and fix this issue on jsbin.

Cause

Absence of //noprotect

Fix

Adding it on top of the code snippet of your jsbin code like below

//noprotect
--Your JS Code --

After a little searching, I was able to find it in their official documentation under the subsection : Loop Protectionhere