Without break statement , the for loop will continue to compare searchName with contact names. As a result, if searchName is one of the contacts but not the last, the last iteration puts ‘Contact not found’ into para.textContent. I think this syntax is a little ugly and illogical, I never use break statement inside a loop. I prefer and it is more understandable to do it like this :
//Search the contact name
var result = contacts.find(function(contact){
return (contact.split(’:’)[0]===searchName);
});
//If contact is found, puts number, else puts not found
if(result){
var splitContact = result.split(’:’);
para.textContent = splitContact[0] + ''s number is ’ + splitContact[1] + ‘.’;
}
else para.textContent = ‘Contact not found.’;