File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments