Skip to content

Instantly share code, notes, and snippets.

@ronan-mch
Forked from sofiawithan-f/Codecademy Issues #1
Last active October 24, 2015 19:07
Show Gist options
  • Save ronan-mch/44d2c98b92614185d189 to your computer and use it in GitHub Desktop.
Save ronan-mch/44d2c98b92614185d189 to your computer and use it in GitHub Desktop.
var square = new Object();
square.sideLength = 6;
square.calcPerimeter = function() {
return this.sideLength * 4;
};
// help us define an area method here
square.calcArea = function(){
return this.sideLength * this.sideLength;
};
var p = square.calcPerimeter();
var a = square.calcArea();
// define a new object with a height and width
var rectangle = new Object();
rectangle.height = 4;
rectangle.width = 3;
// create a new perimeter method
rectangle.calcPerimeter = function(){
return (2 * this.height) + (2 * this.width);
};
console.log("perimeter is " + rectangle.calcPerimeter());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment