1const contacts = ['Chris:2232322', 'Sarah:3453456', 'Bill:7654322', 'Mary:9998769', 'Dianne:9384975'];
2const para = document.querySelector('p');
3const input = document.querySelector('input');
4const btn = document.querySelector('button');
5
6btn.addEventListener('click', function() {
7 let searchName = input.value.toLowerCase();
8 input.value = '';
9 input.focus();
10 for (let i = 0; i < contacts.length; i++) {
11 let splitContact = contacts[i].split(':');
12 if (splitContact[0].toLowerCase() === searchName) {
13 para.textContent = splitContact[0] + '\'s number is ' + splitContact[1] + '.';
14 break;
15 } else {
16 para.textContent = 'Contact not found.';
17 }
18 }
19});