-
Notifications
You must be signed in to change notification settings - Fork 0
number 46 #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
number 46 #10
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| </head> | ||
| <body> | ||
| <script> | ||
| class Shape { | ||
| constructor(length, width) { | ||
| this.length = length; | ||
| this.width = width; | ||
| } | ||
|
|
||
| get area() { | ||
| return this.length * this.width; | ||
| } | ||
|
|
||
| get name() { | ||
| return "Default Shape"; | ||
| } | ||
| } | ||
|
|
||
| class Square extends Shape { | ||
| constructor(length) { | ||
| super(length, length); | ||
| } | ||
|
|
||
| get name() { | ||
| return "Square"; | ||
| } | ||
| } | ||
|
|
||
| class Rectangle extends Shape { | ||
| constructor(length, width) { | ||
| super(length, width); | ||
| } | ||
|
|
||
| get name() { | ||
| return "Rectangle"; | ||
| } | ||
| } | ||
|
|
||
| class Triangle extends Shape { | ||
| constructor(length, width) { | ||
| super(length, width / 2); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| get name() { | ||
| return "Triangle"; | ||
| } | ||
| } | ||
| class Circle extends Shape { | ||
| constructor(radius) { | ||
| super(radius * radius, Math.PI); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually an interesting one! Since a circle doesn't really have a length or height, but what you did is clever since it would still leverage the |
||
| } | ||
|
|
||
| get name() { | ||
| return "Circle"; | ||
| } | ||
| } | ||
| class Cube extends Shape { | ||
| constructor(length, width, height) { | ||
| super(length * width, height); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one might actually be better as something like this. You would also need to override the area function meaning you need to create a new one in this class. |
||
| } | ||
|
|
||
| get name() { | ||
| return "Cube"; | ||
| } | ||
| } | ||
|
|
||
| const shapey = new Cube(2, 2, 2); | ||
| console.log(shapey.area); | ||
| console.log(shapey.name); | ||
|
|
||
| </script> | ||
| </body> | ||
| </html> | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this
constructoris exactly identical as Shape'sconstructor, it is not necessary. It will automatically take everything inside theShapeclass.