a la place d'un else apres une for loop (freeCodeCamp Profile Lookup)

//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 lookUp(firstName, prop){//0 // Only change code below this line for (var i = 0; i < contacts.length; i ++) {//1 //console.log(contacts[i].firstName," ", contacts[i][prop]); if (contacts[i].firstName === firstName && contacts[i][prop] !== undefined) {//2 return contacts[i][prop]; }//-2 else if (contacts[i].firstName === firstName && !contacts[i][prop]) {//2 return "No such property"; }//-2 } // Only change code above this line return "No such contact"; }//-0 // Change these values to test your function lookUp("Bob", "adress");

2 Responses

Did it pass the test? I had to use .hasOwnProperty...
@Luis Lopez Yes, It passed(!)
(I'm embarrassed but in programming I did not take off level zero ;()

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.