-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbusca-numero.html
More file actions
23 lines (21 loc) · 932 Bytes
/
busca-numero.html
File metadata and controls
23 lines (21 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<html>
<script>
//1 - Receber um número como parâmetro
//2 - Executar um for na lista e para cada elemento verificar se e igual ao número buscado
//3 - Quando encontrar, interromper a execução e retornar true
//4 - Se chegar até o fim sem encontrar, retornar false
var lista = [19, 54, 18, 11, 47, 98, 36, 44, 87];
function verificaNumero(numero) {
//começa assumindo que esse número não existe e, a partir da estrutura de repetição, você prova que ele existe
var existe = false;
for (var i = 0; i < lista.length; i++) {
if (lista[i] === numero) {
existe = true;
//o break interrompe o for (ou o while) e continua executando o restante das linhas a seguir
break;
}
}
return existe;
}
</script>
</html>