28. Hello? Yes, This is Dog


#1

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");
yourDog.sayHello();

var myDog = new Dog("dachshund");
myDog.sayHello();


#2

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

and you need a space between the a and quotation mark


#3

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

Thanks!


#4

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