Object Oriented Programming: Create a Method on an Object

i have been trying to solve the challenge on the link ; https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/create-a-method-on-an-object

but i couldnt …my code so far

let dog = {
name: “Spot”,
numLegs: 4,
sayLegs: function() {return "This dog has " + dog.numLegs + “.”;}
};

dog.sayLegs();

you forgot the very last word ‘legs’

2 Likes

you are the best…i think i need to get a pair of glasses like u…laffs

1 Like

let dog = {
name: “Spot”,
numLegs: 4,
sayLegs: function() {return "This dog has " + dog.numLegs + "Legs " + “.”;}
};

dog.sayLegs()

Can you explain this then please?

I’m sorry, I have no clue what you are asking me to explain. If you are struggling with this challenge, click on the ‘ask for help’ button and post directly from there (it will include your full code in proper formatting) and you can ask a specific question or describe your issue there.

You have to use lowerCase l in legs and there’s really no reason for you to seperate legs from ..

should be:

"This dog has " + dog.numLegs +" legs."

Make sure you look to the spaces that you include in your strings as well. You should not use space between legs and the .. But you should between dog.numLegs and legs.

Oh, thank you so much,I spent my 10-15 minutes with this.:relieved:

1 Like