Tell us what’s happening:
It seems right but doesn’t work!
Your code so far
let dog = {
name: "Spot",
numLegs: 4,
sayLegs: function() {
return "This dog has" + dog.numLegs + "legs.";
}
};
dog.sayLegs();
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
.
Challenge: Create a Method on an Object
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
ILM
July 10, 2020, 10:42am
2
maeforest:
dog.sayLegs();
I suggest you tru to put this in a console.log like this:
console.log(dog.sayLegs());
1 Like
The problem is that you’re trying to use dog.numLegs
before dog
actually exists (it only exists after the whole let dog = ...
line). I think you need to use this.numLegs
(where this
refers to the object, before it’s assigned to dog
).
1 Like
I’ve tried that too my friend.
I found out the problem , you should have gaps on either side of “4” when it’s returned.
However thanks for your reply dude.
Bah! I should have run the code before replying.