Why? Learn arrays + random selection.
<p id="quote"></p>
<button onclick="newQuote()">New Quote</button>
<script>
let quotes = [
"Dream big and dare to fail.",
"Do what you can, with what you have.",
"Success is not final, failure is not fatal.",
"Happiness depends upon ourselves."
];
function newQuote() {
let random = Math.floor(Math.random() * quotes.length);
document.getElementById("quote").innerText = quotes[random];
}
</script>
Explanation:
- Quotes stored in an array.
- Random index picks one and displays it.
Leave a Reply