JSFiddle - React, Tailwind, and code Playground

HTML

We have an array of objects representing different people in our contacts lists.

A lookUpProfile function that takes firstName and a property (prop) as arguments has been pre-written for you.

The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.

If both are true, then return the "value" of that property.

If firstName does not correspond to any contacts then return "No such contact"

If prop does not correspond to any valid properties then return "No such property"

JavaScript

//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUpProfile(firstName, prop){
// Only change code below this line

  var contactMatchingFirstName = contacts.filter(function(contact) { return contact.firstName === firstName; });
  
  if(0 === Object.keys(contactMatchingFirstName).length) {
  	return "No such contact";
  }
  
  // dzięki takiej konstrukcji (filter) jest czytelniej
  // dodatkowo jeżeli w zbiorze będzie więcej obiektów posiadających to samo imię
  // możesz spokojnie to sprawdzić tuż nad tym komentarzem 
  // i osoba przeglądająca kod będzie bez zastanawiania wiedziała co się dzieje
  
  var contactWithOwnProperty = contactMatchingFirstName.filter(function(contact) { return contact.hasOwnProperty(prop); });
	
  if(0 === Object.keys(contactWithOwnProperty).length) {
  	return "No such property";
  }
  
  return contactWithOwnProperty[0][prop];

// Only change code above this line
}

// Change these values to test your function
console.info("Akira", lookUpProfile("Akira", "likes")); // likes
console.info("Kristian", lookUpProfile("Kristian", "lastName")); // lastName
console.warn("Kristiana", lookUpProfile("Kristiana", "lastName")); // no such contact
console.info("Sherlock", lookUpProfile("Sherlock", "likes")); // likes
console.warn("Sherlock", lookUpProfile("Sherlock", "likes2")); // no such property
console.info("Harry", lookUpProfile("Harry",...