Hello? Yes, This is Dog


#1

So this is my code, I do not undesrstand why it doesn't print out anything to the console. I pass the task but waht is the point of passing it if I cannot find my mistake. Help please!

The code is what I this it should look like.

I pass it when instead of this.breed i type breed to the console


Replace this line with your code.


#2

Please post a link to the exercise, along with the raw code (not a picture) and any error messages. Thanks.


#3

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

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

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

ReferenceError: breed is not defined


#4

This is where the reference error is thrown. breed is not defined, but this.breed is.


#5

sayHello should print to the console: "Hello this is a [breed] dog"

as in,

    ... "Hello this is a " + this.breed + " dog"

#6

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

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

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

It prints out the breed but the errrs then says :

Oops, try again. It appears that your sayHello method doesn't properly log to the
console 'Hello this is a [breed] dog' where [breed] is the breed of the
Dog


#7

[breed] becomes, this.breed

Be sure your output string matches the one in the instructions (and in the above error message). It must be exact. Use the string I supplied above as a model.


#8

OMG!!! i need reading comprehension exercises not coding.
Thank you very much for your answer.


#9

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