Tell us what’s happening:
Two posts in one day… Oh, dear. I’ve been able to get the first three parts of this challenge ticked off, however, when I then tackled the next step in the process, the first three ticks reverted to crosses, and parts 4 & 5 then became successful. I’m unsure why my ‘if’ statements appear to be tripping each other up. I’ve screen grabbed below to make this clearer:
When I add my next ‘if’ rule, I get this:
As with all issues, I’m sure it’s simple, but I’m even simpler
Your code so far
//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
for (var x = 0; x < contacts.length; x++) {
if (contacts[x].firstName === name && contacts[x].hasOwnProperty("lastName")) {
return contacts[x][prop];
} if (contacts[x].firstName !== name) {
return "No such contact";
}
}
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("Kristian", "lastName");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0
.
Link to the challenge: