The semi-colon is definitely a “gotcha” here. In general though, you should try to indent you code. It will make it more readable to others, plus help you to identify missing syntax (i.e brackets). See below your code is indented and you can quickly figure out what is missing.
function lookUpProfile(name, prop) {
// Only change code below this line
for (var x = 0; x < contacts.length; x++) {
if (contacts[x].firstName === name) {
if (contacts[x].hasOwnProperty(prop)); {
return contacts[x][prop];
}
} else {
return "No such property";
}
return "No such contact"
// Only change code above this line
}
function lookUpProfile(name, prop) {
// Only change code below this line
for (var x = 0; x < contacts.length; x++) {
if (contacts[x].firstName === name) {
if (contacts[x].hasOwnProperty(prop)) {
return contacts[x][prop]
}
} else {
return "No such property"
}
You don’t need to indent for the code to work, but you use it to read your code more easily to see if you have all pieces (for example if all opening brackets have matching closing brackets)
If you just indented you actually have not changed anything
Now that you have indented the code, you should be able to see you have two missing } in the latest (indented) code you posted plus a missing return statement, but you might have accidentally cut the last part off.
function lookUpProfile(name, prop) {
// Only change code below this line
for (var x = 0; x < contacts.length; x++) {
if (contacts[x].firstName === name) {
if (contacts[x].hasOwnProperty(prop)) {
return contacts[x][prop]
}// *this one don't go here you met*//
} else {
return "No such property"
}
return "No such contact"
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("Akira", "likes");
}
```*emphasized text*
Some of your brackets are in the wrong place.
For example you checking for name in first if conditional but your else returning “No such property” which should be returned when you check for property availability.
I am new to JavaScript and I just finished exercise. Anyone reading this reply and found information to be incorrect, please correct.
The if (contacts[x].firstName === name) return “No such contact”.
This statement is checking the condition on the property “firstName” to see if the value of the name is present in the contacts list (for example, if I am passing Bob, it’s checking if the value “Bob” is set to the property firstName in the contacts object.