Need help about last return statement

Hello , i need your help ,
i don’t understand why this don’t work

function lookUpProfile(name, prop){
// Only change code below this line
for (var i=0 ; i<contacts.length ;i++){
if (contacts[i]['firstName']===name){
    if(contacts[i].hasOwnProperty(prop)){
        return contacts[i][prop];
    }
        return "No such property";
        
}
}  
// Only change code above this line
}

than this work :

function lookUpProfile(name, prop){
// Only change code below this line
for (var i=0 ; i<contacts.length ;i++){
if (contacts[i]['firstName']===name){
    if(contacts[i].hasOwnProperty(prop)){
        return contacts[i][prop];
    }
        
        
}
return "No such contact";
}  
// Only change code above this line
}

can you explain me ? thanks a lot

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

1 Like

Oh yes now i see ! we have to iterate all of array that’s why the return is out of the for loops ! thanks a lot