Skip to content
dreamcode
dreamcode
Peaks
Property Lookup
BeginnerJavaScript
Reward: +40 XP
PROBLEM

Property Lookup

Write a function lookupProperty(obj, key) that takes an object and a key string. If the object has that property (not undefined), return its value. Otherwise, return 'Property not found'.

Examples
lookupProperty({ name: "Nova", level: 4 }, "name")
"Nova"
lookupProperty({ name: "Nova" }, "xp")
"Property not found"
solution.js
JAVASCRIPT
Saved as you type

Tests

0 of 3 passing
  • key exists → value
    lookupProperty({ name: "Nova", level: 4 }, "name")
    expected "Nova"
  • key missing → not found
    lookupProperty({ name: "Nova" }, "xp")
    expected "Property not found"
  • empty obj → not found
    lookupProperty({})
    expected "Property not found"
On the line
+40 XP
Pass all 3 tests to claim it.