-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
85 lines (68 loc) · 2.82 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Aula 05</title>
</head>
<body>
<label>Digite uma letra:</label></br>
<input type="text" name="caixa" id="caixa_texto">
<button type="button" onclick="compararLetras()">Comparar</button>
<p id="resultado"></p>
<label>Digite uma Palavra:</label></br>
<input type="text" name="caixa" id="texto_palindromo">
<button type="button" onclick="palindromo()">Testar</button>
<p id="resultado_palindromo"></p>
<label>Digite sua idade:</label></br>
<input type="text" name="caixa" id="idade">
<button type="button" onclick="comp_idade()">Verificar</button>
<p id="resultado_idade"></p>
<script>
function compararLetras(){
const valor_texto = document.getElementById("caixa_texto").value
const res = document.getElementById("resultado")
if(valor_texto[0] == "A"){
res.innerHTML += `Digitou A`
}else if(valor_texto[0] == "a"){
res.innerHTML += `Digitou a`
}
}
function palindromo(){
const valor_texto = String (document.getElementById("texto_palindromo").value)
const res = document.getElementById("resultado_palindromo")
let ordem_certa = []
let ordem_inversa = []
let i=0
let verdadeiro = 0
let cont =0
while(i<= valor_texto.length){
ordem_certa.push(valor_texto[i])
i++
ordem_inversa.push(valor_texto[valor_texto.length-i])
}
while(cont <= valor_texto.length){
if(ordem_certa[cont] == ordem_inversa[cont]){
verdadeiro = verdadeiro +1
}
cont++
}
verdadeiro = verdadeiro -1
if(verdadeiro == valor_texto.length){
res.innerHTML += `É palíndromo`
}else{
res.innerHTML += `Não é palíndromo`
}
}
function comp_idade(){
const idade = Number(document.getElementById("idade").value)
const res = document.getElementById("resultado_idade")
if(idade<18){
res.innerHTML += `Menor de idade`
}else{
res.innerHTML += `Maior de idade`
}
}
</script>
</body>
</html>