While loop issue with Prompt (Adding numbers on Prompt)

Adding two number with prompt input. Pretty simple. The problem is if the user clicks OK without any input or inputs a string, i want the prompt to keep repeating itself. But here, it just repeats once and then disappears.

I wrote this -

<button id='add'> Add </button>

function add() {
    var xp = prompt("First Number");
  while(xp === "" || isNaN(xp) ) {
    var xp = prompt("Please, Enter First Number");
  if (xp) {
  var pt = prompt("Second Number");
    while(pt === "" || isNaN(pt) ) {
    var pt = prompt("Please, Enter Second Number");
    var po = parseInt(xp);
    var co = parseInt(pt);
    var yoo = po+co;
    if (isNaN(yoo)) {
    else {

document.getElementById('add').addEventListener("click", function(){

Link - JS Bin
Help !

It’s Firefox.

Working perfectly on Chrome.

Works for me on Firefox as well.

I can only suggest you use better variable naming :slight_smile:

1 Like

I see in the console there is suggestion to add
// noprotect
as the first line of your JS file. Try it.

@jenovs Thanks. Seems like it’s JS Bin that’s causing the problem in Firefox.

This ^^^

I know they call it ‘coding’, but that doesn’t mean you should aim to be indecipherable! :slight_smile:

1 Like