This problem has condition that couldn't be fullfill any how

Tell us what’s happening:
Describe your issue in detail here.
{
image

problem name = testing objects for property
when cheking for gift should return “pony” and thats tottly fine but the problem is in last line you are aslo asking if obj.hasOwnValue(gift ) this should return “not found” and i think that is not posible to return to two completely diffent velue for one key see the atteched screeen shot i have highlighted the incorret condition kindly fix this and if am wrong than do let me knwo

  **Your code so far**


function checkObj(checkProp) {
// Only change code below this line

let 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
}

console.log(checkObj("district"))

 **Your browser information:**

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

Challenge: Testing Objects for Properties

Link to the challenge:

Read the tests again: The function call includes an object.
In the first test the object has a “gift”-key and thus can return the value.
In the second test, the object DOESN’T have a “gift”-key.

You might be confused because your code is wrong. You are supposed to supply the object as first argument, not to create the object within the code.

1 Like

Thanks for you response but the thing is all thes tests will be executed at the same time so how am i soupous to mate both condition at the same time if you can correct me than I would be more than happy thanks again buddy

You removed the obj argument here.

You must not create an object inside of the function.

1 Like

By writing a function that works on the arguments, instead of creating an object.

In terms of basic addition, your function is basically:

function addNumbers(num){
  let number = 2;
  return number+num}

Now I want to know what 2+5 is and 3+1… how can I declare number to work both times? I can’t. That’s why I create a function add(num1, num2) that just takes two arguments.

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

}

still getting the same error

What is ‘the same error’? That code works fine for me.

I don’t know why but it was not working with the first attempt after starting a new session code worked as expected Thanks for help :>)

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