Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

JavaScript and HTML DOM Reference

const contacts = ['Chris:2232322', 'Sarah:3453456', 'Bill:7654322', 'Mary:9998769', 'Dianne:9384975'];
const para = document.querySelector('p');
const input = document.querySelector('input');
const btn = document.querySelector('button');

btn.addEventListener('click', function() {
  let searchName = input.value.toLowerCase();
  input.value = '';
  input.focus();
  for (let i = 0; i < contacts.length; i++) {
    let splitContact = contacts[i].split(':');
    if (splitContact[0].toLowerCase() === searchName) {
      para.textContent = splitContact[0] + ''s number is ' + splitContact[1] + '.';
      break;
    } else {
      para.textContent = 'Contact not found.';
    }
  }
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: mutation observer 
Javascript :: reverse integer in for javascript 
Javascript :: javascript best online game engine 
Javascript :: Angular passing function as component input 
Javascript :: page scrolling react js 
Javascript :: node js ocr 
Javascript :: unexpected end of json input 
Javascript :: JavaScript ForEach This Argument 
Javascript :: d3 js 
Javascript :: javascript pass this to callback 
Javascript :: javascript inheritance 
Javascript :: React useEffect() the side-effect runs after every rendering 
Javascript :: reverse () method to reverse the array 
Javascript :: socket io websocket connection 
Javascript :: + javascript 
Javascript :: javaScript throw statement 
Javascript :: jquery or operator 
Javascript :: remix js 
Javascript :: how to check if an element already exists in an array in javascript 
Javascript :: vue prop using variable 
Javascript :: request module nodejs 
Javascript :: return data with ajax 
Javascript :: object destruction in javascript 
Javascript :: JavaScript slice() Syntax 
Javascript :: reactjs events list 
Javascript :: some js 
Javascript :: insert property in json file with bash 
Javascript :: react native tdd emzyme 
Javascript :: client.connect is not a function node js mongodb 
Javascript :: find only vowels in string Javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =