28 Hello, Yes this is dog


#1

What is wrong here?

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

};
Dog.prototype.sayHello = function () {
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();


#2

And this is logged in the console:


#3

I think its the comma after hello in your dog prototype function


#4

Haha, omg your right! Thanks so much! :slight_smile:


#5

why my result is empty?


#6

I have the same problem. Nothing shows in the console log


#7

Try putting spaces on both sides of the "+" signs


#8

Omg I did that as well :joy:


#9

I had an problem with my code, took me a while to find, but I found it and fixed it.

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

do you see what i did wrong?
on this part I wrote dog instead of Dog.

 dog.prototype.sayHello = function(){
        console.log('Hello this is a ' + this.breed + ' dog');
    };

this is how it should look:

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

anyways, just thought i'd post in case someone else has the same thing happen.