algoritmos-para-estudar-vic.../Aula3.html
2022-10-29 12:07:16 -04:00

58 lines
1.7 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<p>TESTE 1</p>
<p>
Um texto tem 20 dígitos , a cada 2 dígitos tem um número 0 , os dígitos
são letras aleatórias , faça isso com javascript.
<!--
1.criar a variavel array
2. length = 20
3. gerar as letras aleatórias:
3.1 gerar o indice da letra
3.2 gerar a letra
3.3 fazer um loop para gerar 20 letras
4.substituir por 0 a cada 2 digitos
5. transformar o array em string
-->
</p>
<script>
function randomText() {
const textArray = [];
const alfabeto = "abcdefghijklmnopqrstuvxywzABCDEFGHIJKLMNOPQRSTUVXYWZ";
for (let i = 0; i < 20; i++) {
let letter;
if ((i + 1) % 3 == 0) {
letter = 0;
} else {
let index = parseInt(Math.random() * alfabeto.length);
letter = alfabeto[index];
}
console.log(letter);
textArray.push(letter);
}
console.log(textArray.toString().replace(/\,/g, ""));
}
randomText();
</script>
<p>TESTE 2</p>
<p>
Um dia tem 24 horas, quantos segundos tem em uma semana? faça em
javascript
</p>
<script></script>
<p>TESTE 3</p>
<p>
uma array contendo 40 numeros aleatórios, retornar somente os números
pares divisíveis por 5, faça isso em javascript.
</p>
<script></script>
</body>
</html>