28. Hwllo? Yes, this is dog


#1

https://www.codecademy.com/courses/objects-ii/5/2?curriculum_id=506324b3a7dffd00020bf661#

I am so confused, what am I doing wrong here? Am I delusional and cannot spell prototype correctly? This is the error:
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

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

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

#2

Let's take what you typed and see the results.

Here you have the console log that will return: "Hello this is a dog"
But your code actually returns: "Hello this is adog"

See the diffrence?

So try to add a space between the quote and the dog like:

[...] + this.breed + " dog.");

plus, you need to remove the dot after dog


#3

I tried moving the space around the two sets of strings, as well as make it its own string. Same error, though now it actually prints. Really weird.


#4

A dot. There was a dot after dog, which was not supposed to be there.

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

its supposed to be:

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


#5

Try this 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 ' + this.breed +' dog');
};
var yourDog = new Dog("golden retriever");
yourDog.sayHello();

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


#6

Hey, I've tried your code here: https://repl.it/languages/javascript and it returns fine, aside from the spacing which you're aware about.

I think its just the codecademy window being strange.


#7

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