Basic JavaScript - Testing Objects for Properties - CMEHxO5H7Za_NjER3kHlD

I have been struggling with this since. I don’t seem to understand what is wrong with the code. I have checked the hint and even the solution there doesn’t pass the test. Someone should please help me out here.

  **Your code so far**
function checkObj(obj, checkProp) {
// Only change code below this line
let boolean = obj.hasOwnProperty(checkProp);
/* This is the if function to return the property value
 if the property is present or Not Found if the property is absent */
if (boolean = true) {
  return obj[checkProp];
  return "Not Found";
// Only change code above this line
// This is to see the result
// The result of the example below should be "Not Found" but i am getting undefined
console.log(checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "house"))
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Basic JavaScript - Testing Objects for Properties

Link to the challenge:

I think here is the problem:

if (boolean = true)

what you’re doing here is using wrong sintaxis. You’re using the assignment operator instead of checking if boolean is indeed true.

1 Like

Thank you very much for that. I have been at it for over 30 mins now :slight_smile:
I have got it. I used the == now and it worked perfectly.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.