Random Quote Generator
Keep your content fresh. This script selects a random string from a predefined list and displays it to the user.
"Click the button to get inspired."
Copy the Script
<script>
var quotes = [
"The only way to do great work is to love what you do.",
"Life is what happens when you're busy making other plans.",
"Get busy living or get busy dying."
];
function showQuote() {
var idx = Math.floor(Math.random() * quotes.length);
document.getElementById("quoteBox").innerHTML = quotes[idx];
}
</script>
<div id="quoteBox">Loading...</div>
<button onclick="showQuote()">Next</button>
Frequently Asked Questions
Practically unlimited. Since it's just a JavaScript array, you can add hundreds of strings without impacting performance noticeably.
Yes. Instead of a hardcoded array, you can use `fetch()` to call a public API like 'zenquotes.io' to get fresh content dynamically.
Yes. You can store image URLs in the array instead of text strings and update the `src` attribute of an `
` tag.