Hello? Yes, This is Dog... breed is not defined


#1

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 " + [breed] + " dog");
};

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

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

So I have just completed this exercise with the above code and I can continue onto the next exercise no problem but the console is logging an error message instead of the dogs' breeds and I just wanted to know why??

The error message is "ReferenceError: breed is not defined"

Why is it not defined??


#2

you need to use this.breed, you have access to this variable thanks to this


#3

So it's suppose to be:

console.log("Hello this is a " + this.breed + " dog"); ???


#4

well yes? You make breed accessible in the object with this.breed thanks to this line:

this.breed = breed;

so it makes sense to use this.breed


#5

Awesome thanks :smile:


#6