28. H3llo? Yes, this is dog


#1


It says I'm doing it right but it also says error: breed is not defined. Why is this?

Here's my code.

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();


#2

here:

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

there is a reason you do this, its because now in other methods you can access breed through self


#3

I agree with the last comment, but I will add also:
"dog" >>> " dog"


#4

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