function checkObj(obj, checkProp) {
// Only change code below this line
if(obj.hasOwnProperty(checkProp) == true){
return obj[checkProp];
}
else{
return "Not Found";
}
// Only change code above this line
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36.
Challenge: Testing Objects for Properties
Link to the challenge:
Why can’t I do this ?
function checkObj(obj, checkProp) {
// Only change code below this line
if(obj.hasOwnProperty(checkProp) == true){
return obj.checkProp;
}
else{
return "Not Found";
}
// Only change code above this line
}
As a matter of fact, I use this pattern a lot when working with React.
//Class method syntax
toggle(type) {
this.setState( state => ({[type] : !state[type]}) );
}
//Later you can call it on whatever piece of the state you like
this.toggle('modalCustomer')
this.toggle('modalBooking')
//etc ....
...
In my opinion is a very powerful way of abstraction. Some may consider it a bit too implicit, but that is out of context.