Skip to content

Instantly share code, notes, and snippets.

@alxjrvs
Last active September 30, 2015 14:02
Show Gist options
  • Save alxjrvs/2542c913ff36431a3ca7 to your computer and use it in GitHub Desktop.
Save alxjrvs/2542c913ff36431a3ca7 to your computer and use it in GitHub Desktop.
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