我正在使用JS Bin网站来写这个。做while循环时不提示。 Javascript
循环火灾只有当我给个差(数字)输入一次:
function isInputLeapYear()
{
var year = -1;
var inputOk = true;
do{
year = prompt("Please enter a year to check if it is a leap year \ninput year between 0-9999");
if(year < 0 || 9999 < year) // check input
{
inputOk = false;
alert("\""+year+"\" is not a good year. \nThe input needs to be between 0-9999");
};
}while(inputOk === false);
....
}
的'prompt'函数返回一个'string',而不是一个'number'。您可以查看['parseInt'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt)函数。 –
您需要添加一个'else {inputOk = true; '',否则你的代码对我来说工作得很好。 – 4castle
@DarinDimitrov是正确的。使用parseInt函数。 year = parseInt(输入)。 –