我写了一些javascript代码,在其中我做了一个递归函数。我期待一个数值,但是我收到一个 NaN。我该如何解决这个问题?
<script language="javascript">
function toperform()
{
var proceed=confirm("Do you want to proceed?");
if (proceed==true)
{
var a = checknum("num1");
var b = checknum("num2");
alert("The sum is "+(a+b));
}
else
{
alert("You chose not to proceed!");
}
}
function checknum(arg)
{
var num=parseInt(prompt("Enter "+arg));
if (isNaN(num))
{
alert("Please enter a valid number");
num=checknum(arg);
}
return num;
}
</script>