【发布时间】:2020-06-06 04:47:47
【问题描述】:
我正在开发一个随机密码生成器,它使用来自用户的提示根据用户定义的参数创建密码。到目前为止,我的提示正常工作并记录了正确的响应,但我刚刚开始学习 javascript,对下一步该去哪里有点困惑。我不知道如何组合可能的密码字符的变量和用户响应的变量。任何帮助表示赞赏!这是我到目前为止的代码:
var generateBtn = document.querySelector("#generate");
// Variables that could possibly be included, based on the user responses
var caps = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
var lower = ["a", "b", "c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
var num = [0,1,2,3,4,5,6,7,8,9]
var spec = ['@', '%', '+', '', '/', "'", '!', '#', '$', '^', '?', ':', ',', ')', '(', '}', '{', ']', '[', '~', '-', '_', '.']
// Write password to the #password input
function generatePassword () {
//Attributing variables based on user responses
var pwLength;
pwLength = prompt ("How many characters in your password? Please choose between 8-24.")
if ((pwLength < 24) && (pwLength > 8)) {
console.log (pwLength);
}
else {
alert ("Please use characters between 8-24.");
return false;
};
var pwCaps
pwCaps = confirm("Would you like to include uppercase letters?")
if (confirm){
console.log (pwCaps);
};
var pwSpec
pwSpec = confirm("Would you like to include special characters?")
if (confirm){
console.log (pwSpec);
};
//Creating the length, case style, and character inclusion of the password based on the above variables
【问题讨论】:
-
你得出结论了吗?
标签: javascript variables passwords generator prompt