Skip to content

Instantly share code, notes, and snippets.

@jeffehobbs
Last active February 8, 2018 10:05
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffehobbs/8616064 to your computer and use it in GitHub Desktop.
Save jeffehobbs/8616064 to your computer and use it in GitHub Desktop.
Javascript Random Jersey Headline Generator
<html>
<head>
<title>JS Headline Generator</title>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
</head>
<body>
<div class="container">
<h1></h1>
</div>
<script>
jQuery(document).ready(function() {
//declare arrays
var nouns = ['Chris Christie', 'Bruce Springsteen', 'S.P. Sullivan'];
var scandals = ['shuts down bridge', 'cancels Superbowl', 'caught with armadillo'];
var reasons = ['due to sex scandal', 'for payola scheme', 'in exchange for new Oreo flavor'];
//shuffle through contents of each array, picking one entry per array
var randNoun = nouns[Math.floor(Math.random() * nouns.length)];
var randScandal = scandals[Math.floor(Math.random() * scandals.length)];
var randReason = reasons[Math.floor(Math.random() * reasons.length)];
//place the random entry into the appropriate place in the HTML
jQuery("h1").html("");
jQuery("h1").append(randNoun + "&nbsp;");
jQuery("h1").append(randScandal + "&nbsp;");
jQuery("h1").append(randReason);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment