Skip to content

Commit 99f2a17

Browse files
committed
Primeiro exemplo do strings e datas
1 parent 8e5b8b7 commit 99f2a17

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

cap07/ex7_1.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html lang="pt-br">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Exemplo strings</title>
8+
</head>
9+
10+
<body>
11+
<script>
12+
const anuncio = prompt("Anuncio: "); // Lê o anúncio
13+
let numPalavras = 0 // inicializa o contador
14+
const tam = anuncio.length // obtém o tamanho
15+
for (let i = 0; i < tam; i++) { // percorre os caracteres do anuncio
16+
if (anuncio.charAt(i) == " ") { // se encontrou um espaço
17+
numPalavras++; // incrementa contador
18+
}
19+
}
20+
// Exibe anúncio e número de palavras (que é o número de espaços + 1)
21+
alert(`Anúncio: ${anuncio}\n Números palavras: ${(numPalavras + 1)}`);
22+
</script>
23+
24+
</body>
25+
26+
</html>

0 commit comments

Comments
 (0)