Last active
September 30, 2015 14:02
-
-
Save alxjrvs/2542c913ff36431a3ca7 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 createSquare(length, x, y){ | |
return { | |
length: length, | |
width: length, | |
x: x, | |
y: y, | |
diameter: function(){ | |
var length_squared = Math.pow(this.length, 2); | |
var width_squared = Math.pow(this.width, 2); | |
return Math.sqrt(length_squared + width_squared); | |
}, | |
perimeter: function() { | |
return this.length * 4; | |
}, | |
area: function() { | |
return Math.pow(this.length, 2); | |
}, | |
containsPoint: function(x, y) { | |
var delta = this.width / 2; | |
if(((this.x - delta <= x) && (x <= this.x + delta)) && | |
((this.y - delta <= y) && (y <= this.y + delta))) { | |
return true; | |
A } | |
return false; | |
} | |
} | |
} | |
squareOne = createSquare(20, 1, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment