question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Test and/or solution for the Add Methods After Inheritance challenge seems to be incorrect

See original GitHub issue

After 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:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Nirajn2311commented, Apr 22, 2021

Sure will create a PR soon.

0reactions
raisedadeadcommented, Apr 22, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found