Created
March 1, 2015 04:16
-
-
Save le717/bf7685551a9e523883e7 to your computer and use it in GitHub Desktop.
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
function Rabbit() { | |
this.color = "white"; | |
this.children = []; | |
} | |
Rabbit.prototype.pullFromHat = function() { | |
return !!Math.floor(Math.random() * 2); | |
}; | |
Rabbit.prototype.haveChildren = function() { | |
for (var i = 0; i < 20; i += 1) { | |
this.children.push(new Rabbit()); | |
} | |
}; | |
var rabbit = new Rabbit(); | |
alert(rabbit.pullFromHat()); | |
rabbit.haveChildren(); | |
alert("Number of children: " + rabbit.children.length); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment