gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
js add random text multiple custom
- User
js add random text multiple custom
- Assistant
If you want to add multiple random pieces of custom text using JavaScript, you can do this by storing your texts in an array and then randomly selecting one (or more) to add to your webpage. Here are a few examples depending on your use case:
Example 1: Add a Single Random Text from Multiple Custom Texts
<div id="random-text"></div> <script> const texts = [ "Hello, world!", "Welcome to my site.", "Have a great day!", "JavaScript is awesome!", "Random text here." ]; function getRandomText(arr) { const randomIndex = Math.floor(Math.random() * arr.length); return arr[randomIndex]; } const container = document.getElementById("random-text"); container.textContent = getRandomText(texts); </script>