Griff
June 27, 2022, 7:58pm
1
So I’m trying to go back over the lessons to do the record collection lesson. I’m stuck on this one, I don’t understand how else to solve it other than what I am doing already.
function checkObj(obj, checkProp) {
// Only change code below this line
if (obj.hasOwnProperty(checkProp)){
return obj;
}
else{
return "Change Me!";
}
// Only change code above this line
}
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Firefox/101.0
Challenge: Testing Objects for Properties
Link to the challenge:
ILM
June 27, 2022, 8:00pm
2
What are you asked to return?
Griff
June 27, 2022, 8:01pm
3
The value but I see no way to do that. there is no declared value to return.
ILM
June 27, 2022, 8:02pm
5
which value are you asked to return?
Griff
June 27, 2022, 8:03pm
6
The properties value but I don’t know how. There is no object to get values from the properties.
ILM
June 27, 2022, 8:05pm
8
If there is no object, what are you testing here?
1 Like
Griff
June 27, 2022, 8:06pm
9
Nothing. Which doesn’t make sense because otherwise there isn’t anything to learn. I don’t understand how to test something that doesn’t exist.
Where does it say that obj
means nothing?
Modify the function checkObj
to test if an object passed to the function (obj
) contains a specific property (checkProp
)
Griff
June 27, 2022, 8:07pm
11
its a function according to the lesson. But I don’t know what to do with that information.
ILM
June 27, 2022, 8:07pm
12
Are you familiar with the concept of passing values to a function?
ILM
June 27, 2022, 8:07pm
13
it’s “an object passed to the function”
No. obj
is not a function
test if an object passed to the function (obj
)
Griff
June 27, 2022, 8:09pm
15
Oh sorry I misread. I still don’t know how to return the value.
I don’t know how to get a value when there are no objects to test.
Why do you keep saying this?!?
obj
is an object
I’m missing something here about what you’re missing!
Griff
June 27, 2022, 8:12pm
17
I thought an object needed things inside it?
like this is an object. it has things inside it.
const myDog = {
"name": "Coder",
"legs": 4,
"tails": 1,
"friends": ["freeCodeCamp Campers"]
};
Obj has no things inside it so how do I get the value of it when there is nothing inside it?
The object is set up outside of the function call. You only need to know that obj
is an object that may or may not have the property with the name stored in the variable checkProp
.
ILM
June 27, 2022, 8:13pm
19
Are you familiar with the concept of a variable?
2 Likes
Griff
June 27, 2022, 8:14pm
20
I’ve done this lesson but don’t understand it or why it works. it does something but I don’t know what it means.