I have a html page with 3paragraphs and a button. In my JavaScript file, I created a function that adds 3 new paragraphs to the page each time I hit the button. These 3 new paragraphs should be copies of the existing ones, but each time be added in a randomised order. Here is my function
const body = document.querySelector("#body");
const paragraphs = document.querySelector(".paragraph");
const btnHitMe = document.querySelector("#btn");
const addParagraphs = () => {
Array.prototype.forEach.call(paragraphs, (el) => {
const node = document.createElement("P");
node.innerHTML = el.innerHTML;
body.insertBefore(node, btnHitMe);
});
}
The above code adds the paragraphs successfully. My problem is how do I add these paragraphs in randomised order each time I hit the button?