Skip to content

Instantly share code, notes, and snippets.

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 jacobandresen/1fb6f9664e2b732347590873b8584f02 to your computer and use it in GitHub Desktop.
Save jacobandresen/1fb6f9664e2b732347590873b8584f02 to your computer and use it in GitHub Desktop.
module 3 - lesson 1 - homework
Homework:
---------
In classs you learned about IIFE's, encapsulation and object oriented programming.
You also worked on a example calling library_a.render() and library_b.render().
IIFE's are good for grouping related code in a namespace. Let's say that you have some math related functions . Then
you could do:
var Math = (function () {
return {
Rectangle: function (height, width) {
return {
calcArea: function () {
return height*width;
}
};
},
Triangle: function (A, B, C) {
// .. insert code here ...
}
};
})();
var rectangle = new Math.Rectangle(10,10);
console.log(rectangle.calcArea());
var triangle = new Math.Triangle(6,8,10);
//console.log(triangle.calcArea());
Your task: insert code into the Math.Triangle class that
will make console.log(triangle.calcArea()) print out the area of a triangle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment