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 + " "); | |
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