Skip to content

Instantly share code, notes, and snippets.

@jeffehobbs
Last active January 4, 2016 12:09
Show Gist options
  • Save jeffehobbs/8619782 to your computer and use it in GitHub Desktop.
Save jeffehobbs/8619782 to your computer and use it in GitHub Desktop.
Random Jersey Scandal Generator 2.0
<html>
<head>
<title>JS Headline Generator 2.0</title>
</head>
<body>
<div class="container">
<h1>Did you hear about the Jersey politician who...</h1>
<h1 id="generated">did this thing</h1>
<button id="refreshButton" onclick="refreshScandals();">refresh scandals</button>
</div>
<script>
function refreshScandals () {
//declare arrays
var scandals = ['closed down a bridge', 'canceled the Superbowl', 'helped out fugitive bankers', 'drained the Meadowlands'];
var reasons = ['for political retribution', 'for payola scheme', 'for campaign contributions', 'for an episode of the Sopranos'];
var refreshes = ['yeah yeah', 'so what', 'big deal', 'who cares'];
//shuffle through contents of each array, picking one entry per array
var randScandal = scandals[Math.floor(Math.random() * scandals.length)];
var randReason = reasons[Math.floor(Math.random() * reasons.length)];
var randRefresh = refreshes[Math.floor(Math.random() * refreshes.length)];
//place the random entry into the appropriate place in the HTML
document.getElementById('generated').innerHTML = randScandal + '&nbsp;' + randReason + '?';
document.getElementById('refreshButton').innerHTML = randRefresh;
};
refreshScandals();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment