Profile Lookup Solution Check

Profile Lookup Solution Check
0

#1

Working on Profile Lookup and I cannot for the life of me get more than 2 tests to check. With this solution however it seems to return the right stuff, but all tests stay failing. Is this fundamentally wrong or just not solved 100% exactly as FCC wants it to be? Been trying not to just lookup the answer and skip this. Thank you for any feedback!

//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(name, prop){
// Only change code below this line
//Set variables
var nameList = [];
var propList = [];
//Get value for nameList to use later
for (var i = 0; i < contacts.length; i++){
    if (contacts[i].firstName === name){
        var x = i; //To use in next section
        nameList.push(contacts[i].firstName);
}
}

//Get value for propList to use later
for (let obj in contacts[x]){
    if (obj === prop){
        propList.push(contacts[x][prop]);
    }
}
//Return appropriate values
if (nameList.length === 0){
    return console.log('No such contact');
}else if (propList.length === 0){
    return console.log('No such property');
}else{
    return console.log(propList);
}
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("Akira", "address");

#2

It looks like you’re returning an array where you should return a string. (This can be hard to see in a simple console.log() because of the way that arrays are converted to strings.)


#3

This solution finally worked. The two strings that were being returned we not even counting but removed the arrays. Turns out you can’t return a console.log and have it pass.

//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(name, prop){
// Only change code below this line
//Set variables
var nameList = '';
var propList = '';
//Get value for nameList to use later
for (var i = 0; i < contacts.length; i++){
    if (contacts[i].firstName === name){
        var x = i;//To use in next section
        nameList = contacts[i].firstName;
}
}

//Get value for propList to use later
for (let obj in contacts[x]){
    if (obj === prop){
        propList = contacts[x][prop];
    }
}
//Return appropriate values
if (nameList.length === 0){
    return 'No such contact';
}else if (propList.length === 0){
    return 'No such property';
}else{
    return propList;
}
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("Harry", "address");