28. Hello? Yes, This is Dog - inconsistencies


#1

I need some clarification on the whole [breed] vs this.breed deal. I attempted the exercises two ways:

First, I used this.breed:

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

The above code returns the error message:

"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"

Which I find odd since I can copy this code into something like firebug and it will return:

Hello this is a golden retriever dog.
Hello this is a dachshund dog.

with no issues.

Second, I used [breed]:

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

This results in a contradictory response. The Codecedemy UI tells me "Way to go! Start next lesson" but at the same time also returns an error message:

ReferenceError: Can't find variable: breed

Pasting the same code into firebug results in a similar error:

ReferenceError: breed is not defined

I understand why these error's exist, javascript thinks [breed] is an undefined variable, but why do the Codecademy instructions tell you and reward you for using this format when it doesn't even appear to be correct?


#2

Because as much as the Codecademy engineers ry to make the SCT as intricate as possible. They cannot account for every Javascript loop hole or evasion. :slight_smile:


#3

Okay, so is [breed] even a valid way of doing this? I'm guessing not...


#4

You guessed right. :smile:


#5

You shouldn't put a dot after "dog"

... +" dog");

#6

Theres only one mistake.
The dot (.) after dog xD lol


#7

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


#8

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