Conversation
benspector-mls
left a comment
There was a problem hiding this comment.
Score: 2 - You will need to resubmit this.
Good start on this! Your short responses are good and your code is mostly right. You just aren't invoking super() properly to make your child classes use their parent's constructor. Review how super() works and then resubmit once you've fixed the coding portion.
| super(side1, side2, side3, side4) | ||
| this.side1 = side1; | ||
| this.side2 = side2; | ||
| this.side3 = side1; | ||
| this.side4 = side2; |
There was a problem hiding this comment.
Take a closer look at the instructions, it says that Rectangles should be initialized with 2 arguments: a length and a width instead of the 4 arguments that you have here.
Also, remember that invoking super() will call the Rectangle's parent class constructor which already will assign the values side1 through side4 to this so you don't need to do that work here.
When you change the inputs to the Rectangle constructor to length and width, how can you invoke the super function in such a way that it can still provide the 4 sides needed by the Quadrilateral constructor?
| super(side1, side2, side3, side4) | ||
| this.sideSq = side1 * side1; | ||
| this.side1 = side1 | ||
| this.side2 = side1 | ||
| this.side3 = side1 | ||
| this.side4 = side1 |
There was a problem hiding this comment.
The same feedback that I left for the Rectangle applies here.
| constructor(name, age, grade) { | ||
| this.name = name | ||
| this.age = age | ||
| this.grade = grade | ||
| this.friends = [] | ||
| } | ||
| greet() { | ||
| return `Hello ${this.name}! ` | ||
| } | ||
| getAge() { | ||
| return `${this.name}, You are ${this.age} years old.` | ||
| } | ||
| whatGrade() { | ||
| return `You are in ${this.grade}` | ||
| } | ||
|
|
||
| addFriend(...friendName) { | ||
| this.friends.push(friendName) | ||
|
|
||
| return `Adding ${friendName}...` |
There was a problem hiding this comment.
Nicely done!
|
|
||
| **1. What is inheritance in programming?** | ||
|
|
||
| **Inhertiance** is when a new class has all the functionality of the class in which it derived from while having its own functionality as well. The new class is called a *child* and the other class that it inherits from is refered to as the *parent* class. |
There was a problem hiding this comment.
Excellent! (Except for some typos)
| **Inhertiance** is when a new class has all the functionality of the class in which it derived from while having its own functionality as well. The new class is called a *child* and the other class that it inherits from is refered to as the *parent* class. | |
| **Inheritance** is when a new class has all the functionality of the class which it is derived from while having its own functionality as well. The new class is called a *child* and the other class that it inherits from is referred to as the *parent* class. |
| } | ||
| } | ||
|
|
||
| //Car is this parent class, and BMW is the child class. |
There was a problem hiding this comment.
Nice example!
| Polymorphism is the idea that we can perform a task in multiple forms or ways and is applied of functions and methods. | ||
| Both the parent and child class have the `area()` method, but depending on which object the method is used on each time it is called it will output different things. `ob` is a new instance of `class B`, so when `area` is called on `ob` not only does it calculate `100 * 200` it also `console. logs` "Class B" and the reason it can calculate `100 * 200` is because of the `super class A`. |
There was a problem hiding this comment.
| Polymorphism is the idea that we can perform a task in multiple forms or ways and is applied of functions and methods. | |
| Both the parent and child class have the `area()` method, but depending on which object the method is used on each time it is called it will output different things. `ob` is a new instance of `class B`, so when `area` is called on `ob` not only does it calculate `100 * 200` it also `console. logs` "Class B" and the reason it can calculate `100 * 200` is because of the `super class A`. | |
| Polymorphism is the idea that we can perform a task in multiple forms or ways and is applied to functions and methods. | |
| Both the parent and child class have the `area()` method, but depending on which object the method is used on each time it is called it will output different things. `ob` is a new instance of `class B`, so when `area` is called on `ob` not only does it calculate `100 * 200` it also `console. logs` "Class B" and the reason it can calculate `100 * 200` is because of the `super class A`. |
This is a good example but it isn't the most creative. I don't even know what class A and B are meant to represent. Why do they have an area method? This isn't strictly a problem since the example demonstrates polymorphism but it doesn't make this a particularly engaging example either.
No description provided.