15/30 - 3 ways to "succesfully" complete the section but only one right answer. Why?


#1

The true correct answer was this follow blipet of code::smile:

function Cat(name, breed) {
this.name = name;
this.breed = breed;
}

// let's make some cats!
var cheshire = new Cat("Cheshire Cat", "British Shorthair");
var gary = new Cat("Gary", "Domestic Shorthair");

// add a method "meow" to the Cat class that will allow
// all cats to print "Meow!" to the console
Cat.prototype.meow = function(){
console.log("Meow!");
};

// add code here to make the cats meow!
cheshire.meow();
gary.meow();
//This above code and it's multiple ways to successfully complete the section caused me a lot of unanswered questions.


However, I initially did
console.log(gary.meow);
console.log(cheshire.meow);

It returned [function] [function] respectively.

Then I played around and did
gary.meow
cheshire.meow

This returned a blank console but allowed me to pass.
I am assuming that since I didn't recall it as a method, It didn't go through to the console.log portion of the earlier bit where we defined the method?

I would just like to know the differences in the 3 ways they pass and why they work even though only one is truly correct. Thank you for your help.


#2

It returned [function] because you wrote a reference, not an invocation (call expression)...

gary.meow  => function reference

Were we to write,

gary.meow.toString()

we would get,

function(){
    console.log("Meow!");
}

However, invoking the method, we get

gary.meow(); // Meow!

Hope that answers your question.


#3

Thank you very much for this.