Skip to content

Instantly share code, notes, and snippets.

@riebschlager
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riebschlager/f52e434fa8508bfceedb to your computer and use it in GitHub Desktop.
Save riebschlager/f52e434fa8508bfceedb to your computer and use it in GitHub Desktop.
Three Little Pigs (Javascript Edition)
var pigs = [{
name: 'Doug',
}, {
name: 'Larry'
}, {
name: 'Virgil'
}];
var houses = {
straw: {
strength: 1
},
stick: {
strength: 2
},
brick: {
strength: Infinity
}
};
pigs[0].house = houses.straw;
pigs[1].house = houses.stick;
pigs[2].house = houses.brick;
var wolf = {
name: 'Chuck',
strength: 3
};
for(var i = 0; i < pigs.length; i++) {
console.log('WOLF: Little Pig, Little Pig. Let me in');
if(pigs[i].house.strength > wolf.strength) {
console.log('PIGS: No, no, not by the hair on my chinny chin chin.');
} else {
console.log('PIGS: Oh crap.');
}
}
@coreylight
Copy link

Doesn't run Crysis.

@tazcarper
Copy link

Need to add the ending! If house has chimney, wolf climbs down it. Loop for pigs checking chimney, if true, set fire to true.

@riebschlager
Copy link
Author

I would gladly accept any pull requests :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment