Hello? Yes, this is dog (Needs Debug)


#1


function Dog (breed) {
    this.breed = breed;
    var sayHello =
        console.log("Hello this is a " + this.breed + " dog");
}

// add the sayHello method to the Dog class 
// so all dogs now can say hello


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

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

// This works, but it's not what the lesson wants. How is this fixed?


#2

Why, var sayHello?

Can we really assign a statement to a variable?


#3

Oh. I see (probably) what I did wrong.


#4

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


#5

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