Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Setup
- let 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(name, prop) {
- // Only change code below this line
- let counter = 0;
- let counter2 = 0;
- for (let i = 0; i < contacts.length; i++) {
- let currentObject = contacts[i];
- if (currentObject.firstName === name) {
- counter++;
- }
- for (let j = 0; j < Object.keys(currentObject).length; j++) {
- if (prop === Object.keys(currentObject)[j]) {
- counter2++;
- }
- }
- if (name === currentObject.firstName && counter2 > 0) {
- console.log(currentObject[prop]);
- }
- }
- if (counter === 0) {
- console.log('No such contact');
- }
- if (counter2 === 0) {
- console.log('No such property');
- }
- // Only change code above this line
- }
- // lookUpProfile("Bob", "number");
- lookUpProfile("Kristian", "lastName");
- // lookUpProfile("Akira", "address");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement