Skip to content
← Back to Community
struggling with this 1
Profile icon
garyliggins

Challenge 4:
Write a function called objectSearcher that takes two arguments called myObject which is an object, and property which is a string. When objectSearcher is invoked it will return the value at the property that matches the property string.

Example:

const object1 = {firstName: "Phillip", lastName: "Troutman"};
objectSearcher(object1, "firstName") // returns "Phillip"
objectSearcher(object1, "lastName") // returns "Troutman"

Voters
Profile icon
garyliggins
Comments
hotnewtop
Profile icon
MrEconomical

what have you tried so far?

Profile icon
garyliggins

@MrEconomical

const objectSearcher = (myObject,property) => {
let firstName = 'Phillip'
let lastName = 'Troutman'
console.log(${firstName},${lastName})
}

// UNCOMMENT THESE LINES TO CHECK YOUR WORK
const object1 = {firstName: "Phillip", lastName: "Troutman"};
objectSearcher(object1, "firstName") // returns "Phillip"
objectSearcher(object1, "lastName") // returns "Troutman"

prints to the console:
Phillip,Troutman
Phillip,Troutman

Profile icon
garyliggins

@MrEconomical
also tried this and got the same result, i know im missing a huge step

const firstName = 'Phillip'
const lastName = 'Troutman'
const objectSearcher = (myObject,property) => {
console.log(firstName,lastName)

}

Profile icon
MrEconomical

@garyliggins
to get a property from an object, simply do myObject[property]