-1

How can I load a loop in random order each time the site reloads. Thanks in advance

const names = ["Bob", "Jonas", "Ronald", "Sarah"];

for(let i=0; i < names.length; i++) {
    const j = Math.floor(Math.random() * (i + 1));

    const node = document.createElement("section");
    const pnode = document.createElement("p");
    const article = document.querySelector('article');
    const textnode = document.createTextNode(names[i]);
        
    node.appendChild(pnode);
    pnode.appendChild(textnode);
    article.appendChild(node);

    node.style.backgroundColor = '#'+Math.floor(Math.random()*16777215).toString(16);

    console.log(node)
}
isherwood
  • 52,576
  • 15
  • 105
  • 143
Gych
  • 1

0 Answers0