我不太清楚如何制作,因此生成的密码长度与用户说的应该的一样长。密码生成正常,我只需要帮助实现用户输入]
function start(){
passwordLength();
passwordGenerator();
}
function passwordLength(){
var length = readInt("How many characters long would you like your password to be?: ");
}
function passwordGenerator(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
console.log(passwordGenerator(6));
这样的东西
function start() {
var length = passwordLength();
console.log(length)
console.log(passwordGenerator(length))
}
function passwordLength() {
return prompt("How many characters long would you like your password to be?: ");
}
function passwordGenerator(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
start();
在调用启动函数的地方,使用prompt
获取长度,然后将值发送到passwordGenerator
函数。