Hello everyone, i need someone’s help with this code,
I tried using if statement yet it didn’twork, can anyone help me knowing how to code it? What method to use? And what to type in the console?
Link to the challenge:
Hello everyone, i need someone’s help with this code,
I tried using if statement yet it didn’twork, can anyone help me knowing how to code it? What method to use? And what to type in the console?
Link to the challenge:
I didn’t clearly understand what you mean. If you share your code, I can help you.
How to test if the property on obj exist in checkProp?
You have to use
If(object.hasOwnProperty(property))
return "";
You can easily put it in an if statement, because this method returns a boolean value .
If that is your question?
As the description said, you can use the hasOwnProperty
method.
For example, I have an object called cat
:
const cat = {
name: 'cat',
age: 2,
If I want to check if my object has a property called color
, I will do it like this:
cat.hasOwnProperty("color")
The code above returns false
.
But If I want to check the property name
:
cat.hasOwnProperty("name")
It returns true
.
If you have additional questions feel free to ask. Happy coding!
How to return the property’s value?
What statement to use?
And thanks for your help
Thanks using if-else helped me, yet how to put a return statement to return the property’s value
And thanks for your time and help
No problem!
You can treat any property of an object as if it were an index of an array. This means that myObjectName[property]
will give you the value of the property.
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.