Skip to content

Commit d7ba820

Browse files
authored
Create Inheritance.js
1 parent 7ccef6c commit d7ba820

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Rectangle {
2+
constructor(w, h) {
3+
this.w = w;
4+
this.h = h;
5+
}
6+
}
7+
8+
/*
9+
* Write code that adds an 'area' method to the Rectangle class' prototype
10+
*/
11+
Rectangle.prototype.area= function(){
12+
return this.w * this.h;
13+
}
14+
/*
15+
* Create a Square class that inherits from Rectangle and implement its class constructor
16+
*/
17+
//inherit from rectangle
18+
class Square extends Rectangle {
19+
//create Square constructor
20+
constructor (a){
21+
//call constructor from Rectangle class and insert value
22+
super (a,a);
23+
}
24+
}

0 commit comments

Comments
 (0)