Help please with this challenge

Help please with this challenge
0

#1

Modify the function checkObj to test myObj for checkProp. If the property is found, return that property’s value. If not, return “Not Found”.

This is my input below;

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

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

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

!!any help would be much appreciated.


#2

You don’t have to check the object for only “bed” property,
You function should check for any property put as argument.
If the property is found, then return that property else return “Not Found”.
Does that help?


#3

i tried var checkProp = myObj.hasOwnProperty(); but still not working


#4

Use myObj.hasOwnProperty() inside if statement with checkProp as argument and that should help.


#5

Hello, I’m writing from the phone and do not know the English one, so do not judge strictly…

var myObj = {
gift: 'pony',
pet: 'kitten',
bed: 'sleig'
}

function checkObj(checkProp) {
  if (myObj.hasOwnProperty(checkProp)) {
    return myObj[checkProp]
  } else {
    return 'Not Found'
  }
}
checkObj('bed')

#6

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

Note: Backticks are not single quotes.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#7

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

If you want to compare your solution to others, use the Get a hint button on the challenge and there are alternative solutions you can compare yours to. Also, you can probably search older posts using the forum search feature or google the challenge name and find more there.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Thank you for understanding.


#8

Thanks man :+1: really appreciate the help.