How do I make Math.random pick the same amount of user input value from 4 different arrays?

Good evening smart people!

I am new to programming and I need your help! I got stuck at this code challenge and would love some input on how I can go about this. How do I make Math.random pick the same amount of user input value from 4 different arrays? I am pretty sure the math.random I wrote is wrong. I hit a wall. Thank you ahead for helping! I think this is how you would go about it; By combining the 4 arrays into one array and somehow make the method Math.random pick the random value of what the user input in a prompt. Thank you once again!

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; 
}

2 thoughts on “How do I make Math.random pick the same amount of user input value from 4 different arrays?”

  1. 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) {
              let randomValue = "";
              for (let i = 0; i < userInput; i++)
                   randomValue += userInput[Math.floor(Math.random() * fourArray.length)]; 
              return randomValue; 
         }
    }
    

    Made your array2, array3, array4 to strings.
    Changed fourArray to a one dimensional array by spreading the other arrays.
    Also I made a loop that would create random string in your random function.
    Does this work for you?

    Reply

Leave a Comment