Skip to content

Instantly share code, notes, and snippets.

@mrandyclark
Created January 13, 2011 21:13
Show Gist options
  • Save mrandyclark/778614 to your computer and use it in GitHub Desktop.
Save mrandyclark/778614 to your computer and use it in GitHub Desktop.
var pirates = ["pirate1", "pirate2", "pirate3", "pirate4", "pirate5"];
var distanceToGo = 20;
var newPirates = true;
var getMorePirates = function(pirates) {
pirates.push(
"pirate" +
(pirates.length+1)
);
console.log("we've ordered some new pirates!");
};
var welcomePirates = function() {
console.log("ahoy new pirates!");
};
var swarmbuckleThePirates = function(pirates) {
pirates.pop();
console.log("PIRATES HAVE BEEN SWARMBUCKLED!");
};
while(distanceToGo != 0)
{
console.log("There are " + pirates.length + " pirates");
if(pirates.length < 5) { getMorePirates(pirates); newPirates = true; }
if(newPirates) { welcomePirates(); }
if(Math.floor(Math.random()*3) == 1) { swarmbuckleThePirates(pirates); }
newPirates = false;
distanceToGo = distanceToGo - 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment