Last active
February 8, 2018 10:05
-
-
Save jeffehobbs/8616064 to your computer and use it in GitHub Desktop.
Javascript Random Jersey Headline Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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 + " "); | |
jQuery("h1").append(randScandal + " "); | |
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