Problem with Testing Objects for Properties challenge

Problem with Testing Objects for Properties challenge
0.0 0

#1

So i did everything right but i cant pass it for some reason.

https://imgur.com/kHBoAn3


#2

Could you please post the code and a link to the challenge? Small screenshots saved on Imgur aren’t really a substitute.


#3

The output has to be exactly as mentioned in the instructions. It’s case sensitive.


#4

Tried with a variable but nothing.

// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
  var result = "";
  if (myObj.hasOwnProperty(checkProp)) {
    result =  myObj[checkProp];
  } else {
    result = "Not found";
  }
  
  return result;
  
}

// Test your code by modifying these values
checkObj("gift");

#5

Look closely at which test doesn’t pass and then compare the output of that test with your code.


#6

Ok i just figured out where i failed lol, i was going too quick with lazy brain.


#7

Haha, I think we have all made these mistakes. It’s good practice though, as sometimes you might make a casing mistake in your variables and wonder why the code isn’t working.


#8

My biggest problem is when i dont pass the challenge on my own so i need to look up at hint, even though i understand code and way it works but i feel bad for having to check hint’s. Idk if therew any tips that helps with finding own solutions, i wonder how long does avg developer take to write code on his own with little to no help. I know im beginner, im still using 95% of times freecodecamp challenges and rest is w3schools to look up couple of small details.


#9

Oh I really know your struggle. I’ve been in this for a little longer now, but in the beginning I used to really struggle with my confidence in judging my code and figuring out where it went wrong. I think this comes with a little more practice. Don’t give up, I’m sure you’ll do a great job eventually! Just allow yourself to learn in your own pace, even if that means looking at hints. You’ll soon find you will need them less. Small steps! :slight_smile:


#10

EDIT: I put checkprop in " " so nvm XDD

Hi! I seem to also have this problem but this code didn’t let me pass for some reason…

// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
   var result = "";
  if(myObj.hasOwnProperty("checkProp")){
   result = myObj[checkProp]; 
  }else{
    result = "Not Found";
  }
  
  return result;
}

// Test your code by modifying these values
checkObj("gift");

It passes the not found test but fails all else please help I have been working on it for DAYS.


#11

Taking out the quotation mark on “checkProp” -> . checkProp


#12

ya thanks! I noticed that a while back and got through the challenge.