javascript - 如何从 if-else 语句中调用函数?
问题描述
我试图在它下面的 if-else 语句中调用 pushChar 函数()。我在执行后存储函数的变量是全局的,那为什么我不能调用它呢?
//Creates final array out of random characters from the arraypool that was created by the users criteria inputs.
function pushChar() {
var randomPassword = [];
for (var i = 0; i < pwLength; i++) {
var item = passwordPool[Math.floor(Math.random() * passwordPool.length)];
randomPassword.push(item);
}
return randomPassword;
}
var password = pushChar();
//validate that all of the conditions were met.
var checkUpper = (upperCaseChar.some(ele => password.includes(ele)))
var checkLower = (lowerCaseChar.some(ele => password.includes(ele)))
var checkNumeric = (numericChar.some(ele => password.includes(ele)))
var checkSpecial = (specialChar.some(ele => password.includes(ele)))
console.log(checkUpper);
console.log(checkLower);
console.log(checkNumeric);
console.log(checkSpecial);
if (checkUpper === confirmUpper &&
checkLower === confirmLower &&
checkNumeric === confirmSpecial &&
checkSpecial === confirmNumber) {
console.log(password);
} else {
alert("somethings missing");
pushChar(); //why won't this run??
}
//Presents randomly generated password to the user as a string.
return password.join("");
}
解决方案
推荐阅读
- javascript - 无法在 Javascript 中使用对象键来引用方法
- php - PHP MSSQL num_rows() 不能与 Codeigniter 中的 sqlsrv 驱动程序一起使用
- javascript - javascript数组包含名为空的值
- jquery - 如何使用 Knockoutjs/HTML 属性使文本框部分只读?
- react-admin - react-admin 保存资源正在发送错误资源的一部分
- tensorflow - TF Dataset API:以下顺序是否正确?地图、缓存、随机播放、批处理、重复、预取
- aframe -
仅显示带有 side:back 的图像 - javascript - 如何将升序数字添加到数组中的每 6 项?
- javascript - 将实体绑定到模态
- python - python pandas通过布尔表达式选择loc