-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
159 lines (129 loc) · 4.36 KB
/
script.js
File metadata and controls
159 lines (129 loc) · 4.36 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
function FizzBuzz(){
for (let i = 1; i <= 100; i++) {
if (i%3==0 && i%5==0) {
result = "FizzBuzz"
}
else if (i%5==0) {
result = "Buzz";
}
else if (i%3==0) {
result = "Fizz";
}else{
result = i;
}
document.getElementById("parrafo").innerHTML +=result + "<br>";
}
}
function Vocales(){
let cont_vocales= 0;
let texto = prompt("Ingrese una palabra");
for (let i = 0; i < texto.length; i++) {
if(texto[i]== "a" || texto[i]== "A" ||
texto[i]== "e" || texto[i]== "E" ||
texto[i]== "i" || texto[i]== "I" ||
texto[i]== "o" || texto[i]== "O"||
texto[i]== "u" || texto[i]== "U")
{
cont_vocales+=1;
};
}
console.log(`Su palabra "${texto}" tiene ${cont_vocales} vocales`)
}
function Fibonacci(){
let hasta= +prompt("Hasta qué número desea generar su serie Fibonacci?")
let num1 = 0;
let num2 = 1;
let suma=1;
console.log(num1);
console.log(num2);
// for (let i = 0; i < iteraciones; i++) {
// suma=num1+num2;
// console.log(suma);
// num1=num2;
// num2=suma;
// }
while (suma< hasta) {
console.log(suma);
suma=num1+num2;
num1=num2;
num2=suma;
}
}
function isPalindrome(){
const resultInput = document.getElementById("result");
const textInput = document.getElementById("text-input");
let frase = textInput.value;
//minuscula
let minusculas= frase.toLowerCase();
console.log(minusculas);
//eliminar espacios
let noEspacios = minusculas.replaceAll(" ", "");
console.log(noEspacios);
//let reversa="";
/*for (let letra = 0; letra <= noEspacios.length-1; letra++) {
reversa = noEspacios[letra] + reversa;
}
console.log(`reversa: ${reversa}`);*/
//separar cada letra, se convierte en Array
let separar = noEspacios.split("");
console.log(separar);
//invertir el orden y volver a unir como string
let reversa = separar.reverse();
console.log(reversa);
reversa = reversa.join("");
console.log(reversa);
if (reversa === ""){
resultInput.textContent = `Tu input está vacío, no es divertido.`;
}else if( reversa.length === 1){
resultIntextContent = `Solo introdujiste una letra, no es divertido.`;
}
else if (reversa === noEspacios) {
console.log(`"${frase}" es un palíndromo`);
resultInput.textContent = `"${frase}" es un palíndromo! Qué otro palíndromo conoces?`;
resultInput.style.color= "green";
}else{
console.log(`"${frase}" no es un palíndromo`);
resultInput.textContent = `"${frase}" no es un palíndromo. Prueba con otra frase.`;
resultInput.style.color= "red";
}
}
function palindromeSuggest(){
let textInput = document.getElementById("text-input");
let resultInput = document.getElementById("result");
palindromes = [
"Anita lava la tina", "Somo o no somos", "Isaac no ronca asi", "amor a Roma",
"Sé verlas al revés", "Amo la paloma", "Luz azul", "Yo hago yoga hoy", "la ruta natural",
"dabale arroz a la zorra el Abad", "arepera", "arenera", "Salas", "rotor", "Radar"
];
let randomNum = Math.floor(Math.random()* palindromes.length);
textInput.value = palindromes[randomNum];
resultInput.value="";
}
function AdivinaNumero(){
let numeroSecreto = Math.floor(Math.random()*100);
//console.log(numeroSecreto, typeof numeroSecreto);
let numeroJugador = "";
let contador=0;
do {
numeroJugador= +prompt("Ingrese un número del 1 al 100");
//console.log(numeroJugador, typeof numeroJugador);
if( numeroSecreto > numeroJugador){
alert(`El número es mayor que ${numeroJugador}`);
contador+=1;
}else if (numeroSecreto < numeroJugador){
alert(`El número es menor que ${numeroJugador}`);
contador+=1;
}else if(numeroJugador===numeroSecreto){
alert(`Adivinaste el número en ${contador} intentos!!`)
break;
}
} while (true);
}
function Factorial(){
let numero = +prompt("Ingrese numero")
let accum=1;
for (let i = 1; i <= numero; i++) {
accum *= i;
}
console.log(`${numero} factorial es ${accum}`)
}