I'm a complete beginner trying to learn Javascript. I am trying to complete a problem requiring me to return a value assigned to a key. The function is called getProperty and I am stuck - it keeps returning "should return the value of the property located in the object at the passed in key" every time I attempt to run a test on the code.
var obj = {key: 'value'};
function getProperty(obj, key) {
var o = obj.key;
return(o);
}
console.log(getProperty);
For dynamic attribute names you need to use the bracket
[]
notation instead of the dot notation:Thanks to @Gaby for pointing out that you also need to call the function with valid arguments: