【发布时间】:2021-02-16 05:07:46
【问题描述】:
聪明的人晚上好!
我是编程新手,需要您的帮助!我被困在这个代码挑战中,希望能得到一些关于如何解决这个问题的意见。如何让 Math.random 从 4 个不同的数组中选择相同数量的用户输入值?我很确定我写的 math.random 是错误的。我撞到了一堵墙。提前感谢您的帮助!我认为这就是你的做法;通过将 4 个数组组合成一个数组,并以某种方式使 Math.random 方法选择用户在提示中输入的随机值。再次感谢您!
let array1 = [1, 2, 3];
let array2 = [A, B, C];
let array3 = [a, b, c];
let array4 = [%, @. ^];
let fourArray[array1, array2, array3, array4];
let dnumConfirm = confirm("Do you want numbers in your password?");
let capConfirm = confirm("Do you wantn capital letters in your password?");
let lowConfirm = confirm("Do you want lowercase letters in your password?");
let specialConfirm = confirm("Do you want special characters in your password?");
let userInput = parseInt(prompt("How many capital letters would you like?"));
function random(userInput) {
if(dnumConfirm && capConfirm && lowConfirm && specialConfirm) {
const randomValue = Math.floor(Math.random * Math.floor(userInput(fourArray)));
return randomValue;
}
【问题讨论】:
-
您能否澄清一下“从 4 个不同的数组中选择相同数量的用户输入值”是什么意思?
-
所以,我提示并输入一个整数 14。我希望 Math.random 方法从 4 个数组中选择 14 个字符。所以我想你把这 4 个数组放在一个数组中。我希望这是有道理的。
-
嘿,所以我添加了一个答案,你能检查一下这是不是你想要的吗?
标签: javascript arrays user-input