jueves, 12 de diciembre de 2019

Factorial de un numero java script

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <script>
            function facto() {
                var numero, resp;
                numero = document.getElementById('num').value;
                resp = parseInt(numero);
                for (var i = numero-1; i > 0; i--) {
                    resp *=i;
                }
                document.getElementById('respuesta').value = resp;

            }
        </script>
        <input type="text" id="num"><br><br>
        <input type="submit" onclick="facto()" value="calcular"> <br><br>
        <input type="text" id="respuesta">
    </body>
</html>

No hay comentarios.:

Publicar un comentario