我如何获得一个提示函数,如果为null并在另一个条件下重复,则返回

问题描述 投票:0回答:1

我希望该功能在用户单击取消时停止,如果他们输入的数字不符合条件,则重新运行提示。现在,如果我输入的数字不符合条件,它将停止功能。这是怎么了?谢谢!

function findPasswordLength() {

    passwordLength = prompt("Choose character length \n(at least 8 and no more than 128)");

    if (passwordLength >= 8 && passwordLength <= 128) {
        alert("Your password will be " + passwordLength + " characters long");
    }

    else if (passWordLength === null) {
        return;
    }

    else if (typeof(passwordLength) !== "number" || passwordLength < 8 || passwordLength > 128) {
        findPasswordLength();
    }
}
javascript function prompt
1个回答
-1
投票

您只是在变量名passwordLength上有错字。

else if (passWordLength === null) {

实际上应该是

else if (passwordLength === null) {
© www.soinside.com 2019 - 2024. All rights reserved.