Solution Review: "super" Keyword
In this lesson, we will discuss the solutions to the questions in the previous lesson.
Press + to interact
function Human() {this.name = "Tommy"this.sex = "Male"}class Child extends Human {constructor(){this.age=2;}}var child1 = new Child()
For the code above, you had to answer the following question:
Explanation #
Let’s incorporate each option in our code and see if it’s correct.
Option A: name
and sex
should be passed as parameters to Human()
.
Let’s do that and see the result.
Press + to interact
function Human(name,sex) {this.name = "Tommy"this.sex = "Male"}class Child extends Human {constructor(){this.age=2;}}var child1 = new Child()
The error is still there, so this is not the issue. This makes sense since we are setting definite values for name
...
Access this course and 1400+ top-rated courses and projects.