Tell us what’s happening:
Describe your issue in detail here.
Your code so far
video uses first name exactly how i use first name yet i get this error TypeError: Cannot read properties of undefined (reading ‘firstName’)
// Setup
const 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
var c = 3;
do { c--
if
( contacts[c].firstName != name && contacts[c].hasOwnProperty(prop) == prop ){
console.log("No such contact");
}else if
( contacts[c].hasOwnProperty(prop) == false && contacts[c].firstName == name ){
console.log("No such property");
}else if
( contacts[c].hasOwnProperty(prop) && contacts[c].firstName == name ){
console.log(prop);
}
}
while (c >= 0 );
//only change code above this line
}
lookUpProfile("Akira", "likes");
lookUpProfile("Sherlock", "likes");
lookUpProfile("Harry", "likes");
lookUpProfile("Bob", "number");
lookUpProfile("Bob", "potato");
lookUpProfile("Akira", "address");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
Challenge: Basic JavaScript - Profile Lookup
Link to the challenge: