vendredi 23 septembre 2022

How to get random characters from multiple different arrays in JavaScript

const array1 = ["A", "b", "C", "D", "f"]
const array2 = ["❤️", "🔥", "👋", "🦑", "😅"]
const array3 = ["0", "1", "2", "3", "4", "5"]


function renderItem() {
    let randomI = Math.floor(Math.random() * array1.length)
    console.log(array2[randomI])
}


function generateRandom () {
    let randomValue = ""
    for(let i = 0; i < 4; i++) {
        randomValue += renderItem()
    }
    return randomValue
}

I create an input field in HTML where the user can select a number between (6 - 18). and two input checkboxes. if both or one of them are checked✅ I want to generate random characters from three(3) of the arrays or from two(2) different arrays. if none of theme are not checked I want to generate random characters from the first array.

now my question is how do I get random e.g.(10) characters from those 3 different arrays?




Aucun commentaire:

Enregistrer un commentaire