question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Testing Objects for Properties needs clarification.

See original GitHub issue

Challenge Testing Objects for Properties has an issue. User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36. Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:


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

function checkObj(checkProp) {
 if(myObj.hasOwnProperty(checkProp)){
   return myObj[checkProp];
 }
  return "Not Found";
}

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

edited by mod

Issue Description

Clarity issue on this problem - User allowed to use dot operator to access value. however using dot operator(obj.prop NOT obj.“prop” as given in the paramater) in this instance creates undefined value - out of scope of this exercise

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Manisha11sepcommented, Mar 24, 2017

Hi @mszaf @rdsandovalm my code is working find for all the values. var myObj = { gift: “pony”, pet: “kitten”, bed: “sleigh” };

function checkObj(checkProp) { // Your Code Here if (myObj.hasOwnProperty(checkProp)){ return myObj[checkProp]; } else{ return “Not Found”; } }

// Test your code by modifying these values checkObj(“pet”);

Its really weird that its showing error for using .operator instead of [] while accessing the values of myObj. I searched online and everywhere it saying we can access property of a object in two ways:-

  1. ObjectName[“propertyName”]
  2. ObjectName.propertyName I hope it will help.
1reaction
systimoticcommented, Dec 2, 2016

Hi @mszaf! Thank you for reporting this issue.

It took me a bit to understand what you were saying, so to save others the same struggle, here’s what I believe this is about. This challenge does not mention how to return the value when it is present. Campers could try to return the value as return myObj.checkProp rather than return myObj[checkProp] The previous challenge talks about the correct method, so I feel this is probably fine as it is.

What do you all think?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Basic JavaScript: Testing Objects for Properties
Modify the function checkObj to test if an object passed to the function ( obj ) contains a specific property ( checkProp )....
Read more >
Can someone clarify "Testing Objects for properties" for me ...
Okay, so I understand that this is checking if myObj has it's property of "top" or "middle" or whatever. Below is the task...
Read more >
javascript (Testing objects for properties)
Now, using Conditional (ternary) Operator we need to check if the required property in the object is found or not.
Read more >
Basic JavaScript Lesson:Testing Objects for Properties
Certification: JavaScript Algorithms and Data StructuresCourse: Basic JavaScriptLesson: Testing Objects for PropertiesfreeCodeCamp tutorialIn ...
Read more >
Testing Objects for Properties in JavaScript - YouTube
By watching this video, you will learn how to test objects for properties in JavaScript. The platform used throughout this video is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found