<div style="height: 300px;">
<button id="btn">
Click here for a random quote!
</button>
<pre id="target"></pre>
</div>
JavaScript
const quotes = [
`A good programmer looks both ways before crossing a one-way street.`,
`A computer program does what you tell it to do, not what you want it to do.`,
`Only half of programming is coding. The other 90% is debugging`,
`The best thing about a boolean is even if you are wrong, you are only off by a bit.`,
`There is nothing quite so permanent as a quick fix.`,
`There’s no test like production.`
];
const button = document.getElementById('btn');
const pre = document.getElementById('target');
btn.addEventListener('click', (e) => {
pre.innerHTML = quotes[Math.floor(Math.random() * quotes.length)];
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.