28. Hello? Yes, This is Dog


When I run the code, it says I passed, but in the Console it logs: " ReferenceError: breed is not defined"... Can't figure out why. Is there something wrong with my code or is it the console?

function Dog (breed) {
    this.breed = breed;

// add the sayHello method to the Dog class 
// so all dogs now can say hello
Dog.prototype.sayHello = function () {
    console.log("Hello this is a" + this[breed] + ' dog');

var yourDog = new Dog("golden retriever");

var myDog = new Dog("dachshund");


this would just be this.breed, not this[breed]

and you need a space between the a and quotation mark


Thanks - earlier I had tried with this.breed and it showed an error message, I think because I forgot the space after a".



This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.