function takeANumber() {
let startHealth = parseInt(prompt("Please enter a positive number:"));
// I am recursively calling the same function within an if block to ensure that the input is a valid number greater than zero. Is this considered good practice?
if (isNaN(startHealth) || startHealth <= 0) {
takeANumber();
}
// checkIfNumber();
let playerHealth = startHealth;
let monsterHealth = startHealth;
adjustHealthBars(startHealth);
}
I am attempting to receive a positive number through a function call. Within the function, I have included an if statement to verify if the input is numeric. If it's not, the function is called again. My concern is whether it is safe or considered good practice to call a function within itself in a larger project codebase.