ga13er
August 25, 2022, 1:09am
#1
Tell us what’s happening:
Describe your issue in detail here.
**Your code so far**
function checkObj(obj, checkProp) {
// Only change code below this line
return "Change Me!";
// Only change code above this line
}
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36
Challenge: Basic JavaScript - Testing Objects for Properties
Link to the challenge:
Welcome to the forum!
What issues do you have with this task?
ga13er
August 25, 2022, 1:20am
#3
Adam There is a Problem with the challenge I think.
Check this:
checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift")
should return the string pony
.
Passed:checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "pet")
should return the string kitten
.
Passed:checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "house")
should return the string Not Found
.
Passed:checkObj({city: "Seattle"}, "city")
should return the string Seattle
.
Passed:checkObj({city: "Seattle"}, "district")
should return the string Not Found
.
Failed:checkObj({pet: "kitten", bed: "sleigh"}, "gift")
should return the string Not Found
.
on the very first pass you see “gift” should return “pony”.
and on the last failed why do I see “gift” should return Not Found
Different objects are passed into the function on different tests.
ga13er
August 25, 2022, 1:43am
#5
Would you mind can you please provide me the solution.
We aren’t allowed to write solutions for users.
You need to use the obj passed into the function.
ga13er
August 25, 2022, 1:49am
#7
See Than:
function checkObj(obj, checkProp) {
// Only change code below this line
obj = {
gift: "pony",
pet: "kitten",
bed: "sleigh",
city: "Seattle"
};
if(obj.hasOwnProperty(checkProp)) {
return obj[checkProp];
} else {
return "Not Found";
}
// Only change code above this line
}
ga13er
August 25, 2022, 1:50am
#9
if I delete this how does the code works without object items
ga13er:
checkObj(obj, checkProp)
The object is a function argument
ga13er
August 25, 2022, 1:53am
#11
than once we initialize it. its Automatically became Global
and if I need to delete this how can I pass all without initializing it inside the function either In the comments
You don’t put the object anywhere. The values of the arguments are determined when the function is called.
This says obj = {pet: "kitten", bed: "sleigh"}
and checkProp = "gift"
for the function call.
And
The objects look different to me
ga13er
August 25, 2022, 2:04am
#15
Still Stuck I think I should work hard to understand this.
Did you try deleting the part I said to delete?
ga13er
August 25, 2022, 2:06am
#18
function checkObj(obj, checkProp) {
// Only change code below this line
obj = {
};
if(obj.hasOwnProperty(checkProp)) {
return obj[checkProp];
} else {
return “Not Found”;
}
// Only change code above this line
}
ga13er:
obj = {
};
Delete all of this! The whole thing.
ga13er
August 25, 2022, 2:07am
#20
You mean like this:
function checkObj(obj, checkProp) {
// Only change code below this line
if(obj.hasOwnProperty(checkProp)) {
return obj[checkProp];
} else {
return "Not Found";
}
// Only change code above this line
}