3
respuestas

[Duda] Proyector FINAL

hola compañeros, A ver si alguno de ustedes puede apoyar con la solución de boton, algo estoy haciendo mal que no hace el llamado de mi operacion arimetica de una calculadora suma, resta, multiplicacion y division. este no tiene arreglos, es con sentencia IF


<html >
<h2>==Calculadora ==</h2>

<script>
    var input = document.querySelector("input");
    // SELECCION DE FOCO O EN LA POSICION DE INICIO DE NUEVO
    input.focus();

        function saltoLinea(){
        document.write("<br>");
        } 
        function mostrar(frase) {
            document.write(frase);
            saltarLinea();
        }
        //VALIDAR BOTON DE OPCIONES DEL 1 AL 5
        function verificar(){
            var encontrado = false; //booleano

            // REALIZAR LA SUMA
            if(parseInt(input.value) == 1){

                document.write("Has seleccionado la suma");
                saltoLinea();
                var a = parseInt(prompt ("Seleccionar opcion"));    
                saltoLinea();
                var b = parseInt(prompt ("Seleccionar opcion"));
                resultador = (a+b);
                mostrar (resultador);
            }
            // REALIZAR LA RESTA
            if(parseInt(input.value) == 2){


                document.write("Has seleccionado la resta");
                saltoLinea();
                var a = parseInt(prompt ("Seleccionar opcion"));    
                saltoLinea();
                var b = parseInt(prompt ("Seleccionar opcion"));
                resultador = (a-b);
                mostrar (resultador);
            }
            // REALIZAR LA MULTIPLICACION
            if(parseInt(input.value) == 3){


                document.write("Has seleccionado la multiplicacion");
                saltoLinea();
                var a = parseInt(prompt ("Seleccionar opcion"));    
                saltoLinea();
                var b = parseInt(prompt ("Seleccionar opcion"));
                resultador = (a*b);
                mostrar (resultador);
            }
            // REALIZAR LA DIVISION
            if(parseInt(input.value) == 4){


                document.write("Has seleccionado la Divicion");
                saltoLinea();
                var a = parseInt(prompt ("Seleccionar opcion"));    
                saltoLinea();
                var b = parseInt(prompt ("Seleccionar opcion"));
                resultador = (a/b);
                mostrar (resultador);
            }
            // REALIZAR LA EXPONENIAL
            if(parseInt(input.value) == 5){

                document.write("Has seleccionado la Exponencial");
                saltoLinea();
                var a = parseInt(prompt ("Seleccionar opcion"));    
                resultador = (a*a);
                mostrar (resultador);
            }
            else{

            alert ("Selecionar del 1 al 5");

            }


            // BOTON SIN SELECCION DE NUMERO
            if (encontrado == false){

            alert("No a ingresado el numero");
            }    

            // LIMPIAR EL INPUT EN BLANCO
            input.value= "";
            // SELECCION DE FOCO O EN LA POSICION DE INICIO DE NUEVO
            input.focus();

        }


// EL USUARIO SELECIONA EL BOTON..!
 var button = document.querySelector("button");
// ENVIA LA RESPUESTA DEL BOTON DE VERIFICAR =  DEL  1 AL 5
button.onclick = verificar;


</script>



Menu de operacion arimeticas
<br>
1.- Suma
<br>
2.- Resta
<br>
3.- Multiplicacion
<br>
4.- Division
<br>
5.- Potencia
<br>
<br>
Selecionar del 1 al 5
<br>
<input> <button>Selecciono</button>


</html>
3 respuestas

Saludos tu lógica esta bien implementada solo te falta organizar un poco tu código eso incluye los textos de ayuda de cada operación aritmética

<meta charset="utf-8" />

<html>
<body>

    <h1>==Calculadora ==</h1>

    <h2>
        Menu de operacion arimeticas
        <br>
        1.- Suma
        <br>
        2.- Resta
        <br>
        3.- Multiplicacion
        <br>
        4.- Division
        <br>
        5.- Potencia
        <br>
        <br>
        Selecionar del 1 al 5
        <br>
    </h2>

    <input />
    <button>Selecciono</button>

    <script>
        var input = document.querySelector("input");
        // SELECCION DE FOCO O EN LA POSICION DE INICIO DE NUEVO
        input.focus();

        function saltoLinea() {
            document.write("<br>");
        }
        function mostrar(frase) {
            document.write(frase);
            saltarLinea();
        }
        //VALIDAR BOTON DE OPCIONES DEL 1 AL 5
        function verificar() {
            var encontrado = false; //booleano

            // REALIZAR LA SUMA
            if (parseInt(input.value) == 1) {

                document.write("Has seleccionado la suma");
                saltoLinea();
                var a = parseInt(prompt("Seleccionar opcion"));
                saltoLinea();
                var b = parseInt(prompt("Seleccionar opcion"));
                resultador = (a + b);
                mostrar(resultador);
            }
            // REALIZAR LA RESTA
            if (parseInt(input.value) == 2) {

                document.write("Has seleccionado la resta");
                saltoLinea();
                var a = parseInt(prompt("Seleccionar opcion"));
                saltoLinea();
                var b = parseInt(prompt("Seleccionar opcion"));
                resultador = (a - b);
                mostrar(resultador);
            }
            // REALIZAR LA MULTIPLICACION
            if (parseInt(input.value) == 3) {

                document.write("Has seleccionado la multiplicacion");
                saltoLinea();
                var a = parseInt(prompt("Seleccionar opcion"));
                saltoLinea();
                var b = parseInt(prompt("Seleccionar opcion"));
                resultador = (a * b);
                mostrar(resultador);
            }
            // REALIZAR LA DIVISION
            if (parseInt(input.value) == 4) {

                document.write("Has seleccionado la Divicion");
                saltoLinea();
                var a = parseInt(prompt("Seleccionar opcion"));
                saltoLinea();
                var b = parseInt(prompt("Seleccionar opcion"));
                resultador = (a / b);
                mostrar(resultador);
            }
            // REALIZAR LA EXPONENIAL
            if (parseInt(input.value) == 5) {

                document.write("Has seleccionado la Exponencial");
                saltoLinea();
                var a = parseInt(prompt("Seleccionar opcion"));
                resultador = (a * a);
                mostrar(resultador);
            }
            else {
                alert("Selecionar del 1 al 5");
            }


            // BOTON SIN SELECCION DE NUMERO
            if (encontrado == false) {

                alert("No a ingresado el numero");
            }

            // LIMPIAR EL INPUT EN BLANCO
            input.value = "";
            // SELECCION DE FOCO O EN LA POSICION DE INICIO DE NUEVO
            input.focus();
        }


        // EL USUARIO SELECIONA EL BOTON..!
        var button = document.querySelector("button");
        // ENVIA LA RESPUESTA DEL BOTON DE VERIFICAR =  DEL  1 AL 5
        button.onclick = verificar;

    </script>

</body>

</html>

hola Duvian Arley Vargas Alvarez !!

muchas gracias por la solución y el apoyo. y el acopodo del codigo.

Saludos