Test and/or solution for the Add Methods After Inheritance challenge seems to be incorrect
See original GitHub issueAfter seeing a question on the forum concerning the Add Methods After Inheritance challenge, I am wondering if either the following test’s text
and/or textString
is incorrect.
- text: <code>Dog</code> should have the <code>bark()</code> method as an <code>own</code> property.
testString: assert(Dog.prototype.hasOwnProperty('bark'));
If the bark
method is really an own
property, then when I write the following:
const beagle = new Dog();
for (let prop in beagle) {
if (beagle.hasOwnProperty(prop) {
console.log(prop);
}
}
I would expect to see bark
displayed in the console, but do not.
The current test is checking if bark
is part of Dog’s prototype, which would not be an own
property would it? If I am correct, then the solution (below) is incorrect as it adds bark
to Dog’s prototype.
function Animal() {}
Animal.prototype.eat = function() {
console.log("nom nom nom");
};
function Dog() {}
// Add your code below this line
Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;
Dog.prototype.bark = function() {
console.log("Woof!");
};
// Add your code above this line
let beagle = new Dog();
beagle.eat(); // Should print "nom nom nom"
beagle.bark(); // Should print "Woof!"
Shouldn’t the solution really be a matter of changing the original function declaration of Dog to be the following or should the test text
not mention the own
property?
function Animal() {}
Animal.prototype.eat = function() {
console.log("nom nom nom");
};
function Dog() {
// Only change code below this line
this.bark = function() {
console.log("Woof!")
}
// Only change code above this line
}
Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;
let beagle = new Dog();
beagle.eat(); // Should print "nom nom nom"
beagle.bark(); // Should print "Woof!"
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
CITI Training Flashcards - Quizlet
Study with Quizlet and memorize flashcards containing terms like A subject participates in a drug study because treatment is available at no or...
Read more >Untitled - Snap!
Recursively sort the rest of the list, then insert the one left-over item where it belongs in the list, like adding a card...
Read more >Occasional paternal inheritance of the germline-restricted ...
Most if not all songbirds possess a germline-restricted chromosome (GRC) which is believed to be exclusively maternally inherited. However, we show that, ...
Read more >IDIF Implementors Forum - Issue Log - STEP Tools, Inc.
It seems imperative to me that the information exchanged in any implementation form be equivalent to any other form. The information is not...
Read more >Testing object-oriented software: a survey
'Both testing and maintenance are simplified by an object-oriented approach, but the traditional methods used in these phases are not significantly altered.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sure will create a PR soon.
Hi @Nirajn2311 will you be interested in making a PR. I understand because haven’t had any objections to your recommendation in a while we should go forth with this.
Thanks.