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)) {
document.write("");
}
else {
document.write(yoo);
}
}
}
document.getElementById('add').addEventListener("click", function(){
add();
});
Link - JS Bin
Help !