Created
May 12, 2020 02:04
-
-
Save Bolinha1/b747546d00335e907f06f8ea15d09bfd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var contatos = [ | |
'Anderson:anderson@teste.com', | |
'Bolinha:bolinha@teste.com', | |
'Juliano:juju@teste.com', | |
'Otávio:otavio@teste.com' | |
]; | |
var paragrafo = document.querySelector('p'); | |
var input = document.querySelector('input'); | |
var btn = document.querySelector('button'); | |
btn.addEventListener('click', function () { | |
var nomePesquisa = input.value; | |
input.value = ''; | |
input.focus(); | |
for (var i = 0; i < contatos.length; i++) { | |
var contatosNome = contatos[i].split(':'); | |
if (contatosNome[0] === nomePesquisa) { | |
paragrafo.textContent = contatosNome[0] + ' seu email é: ' + contatosNome[1] + '.'; | |
break; | |
} else { | |
paragrafo.textContent = 'Contato não encontrado.'; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment