Ya estoy inscrito ¿Todavía no tienes acceso? Nuestros Planes
Ya estoy inscrito ¿Todavía no tienes acceso? Nuestros Planes
1
respuesta

¡No hay ingredientes repetidos aquí!

<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>
1 respuesta

Hola estudiante, Gracias por compartir la solución de tus ejercicios con nosotros. ¿Sabias que puedes interactuar con el resto de tus compañero por nuestro Discord? En Discord el alcance es mayor, la interacción es inmediata y llega a más compañeros de esta forma el foro solo quedaría para esclarecer cualquier duda que puedas tener sobre el contenido de los cursos. Un saludo!

Si este post te ayudó, por favor, marca como solucionado ✓. Continúa con tus estudios