samedi 2 mai 2020

Random item from the array without repeating elements in Javascript

I don't want the function to repeat elements taken from the array

function Gen() {
    let Qu = ["Yazeed", "Ammar", "Marwan", "Othman", "Sameh", "Amro", "Ibraheem"];
    let p1 = document.getElementById("demo1");
    let text = " ";
    for (let i = 0; i < 4; i++) {  //Qu.length = 7
            let p = Qu[Math.floor(Math.random() * Qu.length)];
            text+= "This is " + p  + "<br>";
    }
    p1.innerHTML = text;
}



Aucun commentaire:

Enregistrer un commentaire