Answer the question
In order to leave comments, you need to log in
Will there be a stack overflow and how to check it?
function readNumber() {
let answer = prompt('Введите число?', 0);
if (isFinite(answer) == true && answer != '') {
alert('Это число: ' + answer);
} else {
readNumber();
}
}
readNumber();
Answer the question
In order to leave comments, you need to log in
In setTimeout wrap then there will be no stack overflow
function readNumber() {
let answer = prompt('Введите число?', 0);
if (isFinite(answer) == true && answer != '') {
alert('Это число: ' + answer);
} else {
setTimeout(readNumber, 0);
}
}
well, if the user is very slow-witted
function readNumber(n) {
console.log(n)
if(n > 10000) {
return 'DONE!'
} else {
return readNumber(n + 1)
}
}
readNumber(0)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question