<script>
let ingredientes = [];
let cantidad = parseInt(prompt("¿Cuántos ingredientes vas a añadir?"));
let contador = 1;
while (contador <= cantidad) {
let ingrediente = prompt("Informe el ingrediente " + contador);
let existeIngrediente = false;
for (let i = 0; i < ingredientes.length; i++) {
if (ingrediente == ingredientes[i]) {
existeIngrediente = true;
break;
}
}
if (existeIngrediente == false) {
ingredientes.push(ingrediente);
contador++;
} else {
alert("El alimento que ingresó ya existe, debe ingresar otro diferente");
}
}
console.log(ingredientes);
//FUNCIONES5
function aleatorio() {
return Math.round(Math.random() * 10);
}
function sortearNumeros(cantidadDeNumeros) {
let auxNumerosSecretos = [];
let contador = 1;
while (contador <= cantidadDeNumeros) {
let auxAleatorio = aleatorio();
let existeValor = false;
for (let i = 0; i < auxNumerosSecretos.length; i++) {
if (auxAleatorio == auxNumerosSecretos[i] && auxAleatorio != 0) {
existeValor = true;
break;
}
}
if (existeValor == false) {
contador++;
auxNumerosSecretos.push(auxAleatorio);
}
}
return auxNumerosSecretos;
}
function verificar() {
let encontrado = false;
for (let posicion = 0; posicion < numerosSecretos.length; posicion++) {
if (parseInt(input.value) == numerosSecretos[posicion]) {
alert("Usted acertó");
encontrado = true;
break;
}
}
if (!encontrado) {
alert("Usted erró");
}
input.value = "";
input.focus();
}
function imprimirTexto(texto) {
document.write(texto + "<br>");
}
</script>