Calculator in javascript+ Html no Quit result

Asked

Viewed 167 times

-2

I don’t know what I did wrong, I’m starting on this and I followed the booklet, but the mistake: can someone help me?

    <!DOCTYPE html>
<html>
<head>
    <title>Calculadora Basica</title>
    <script type="text/javascript">
        function soma(){
            var numero1 = parseInt(document.getElementById('n1').values);
            var numero2 = parseInt(document.getElementById('n2').values);
            var resultado = numero1 + numero2;
            document.getElementById('result').value = resultado;
        }
        function subs(){
            var numero1 = parseInt(document.getElementById('n1').values);
            var numero2 = parseInt(document.getElementById('n2').values);
            var resultado = numero1 - numero2;
            document.getElementById('result').value = resultado;
        }
        function multi(){
            var numero1 = parseInt(document.getElementById('n1').values);
            var numero2 = parseInt(document.getElementById('n2').values);
            var resultado = numero1 * numero2;
            document.getElementById('result').value = resultado;
        }
        function divis(){
            var numero1 = parseInt(document.getElementById('n1').values);
            var numero2 = parseInt(document.getElementById('n2').values);
            var resultado = numero1 / numero2;
            document.getElementById('result').value = resultado;
        }

        window.onload = function(){
            alert("Calculadora. Seja Bem vindo - Teste de Alert");
        }
    </script>
</head>
<body>
            <form>
                <div style="text-align:center; ">
                    Calculadora Basica
                    <br>
                    <input type="number" name="n1" id="n1">
                    <input type="button" value="+" onclick="soma();">
                    <input type="button" value="-" onclick="subs();">
                    <input type="button" value="x" onclick="multi();">
                    <input type="button" value="/" onclick="divis();">      
                    <input type="number" name="n2" id="n2">
                    =
                    <input type="number" name="resultado" id="result" >


                </div>
            </form>
        </body>
        </html>

I don’t know what it could be, it’s been 30 minutes since I changed the code and nothing

  • You are picking up "values" the correct would be to use the Value method;

2 answers

2

Dude, you just misspelled the property value, you left as values.

The right thing to do:

var numero1 = parseInt(document.getElementById('n1').value);
var numero2 = parseInt(document.getElementById('n2').value);
  • Obg tb friend....

2


   <!DOCTYPE html>
<html>
<head>
    <title>Calculadora Basica</title>
    <script type="text/javascript">
        function soma(){
            var numero1 = parseInt(document.getElementById('n1').value);
            var numero2 = parseInt(document.getElementById('n2').value);
            var resultado = numero1 + numero2;
            document.getElementById('result').value = resultado;
        }
        function subs(){
            var numero1 = parseInt(document.getElementById('n1').value);
            var numero2 = parseInt(document.getElementById('n2').value);
            var resultado = numero1 - numero2;
            document.getElementById('result').value = resultado;
        }
        function multi(){
            var numero1 = parseInt(document.getElementById('n1').value);
            var numero2 = parseInt(document.getElementById('n2').value);
            var resultado = numero1 * numero2;
            document.getElementById('result').value = resultado;
        }
        function divis(){
            var numero1 = parseInt(document.getElementById('n1').value);
            var numero2 = parseInt(document.getElementById('n2').value);
            var resultado = numero1 / numero2;
            document.getElementById('result').value = resultado;
        }

        window.onload = function(){
            alert("Calculadora. Seja Bem vindo - Teste de Alert");
        }
    </script>
</head>
<body>
            <form>
                <div style="text-align:center; ">
                    Calculadora Basica
                    <br>
                    <input type="number" name="n1" id="n1">
                    <input type="button" value="+" onclick="soma();">
                    <input type="button" value="-" onclick="subs();">
                    <input type="button" value="x" onclick="multi();">
                    <input type="button" value="/" onclick="divis();">      
                    <input type="number" name="n2" id="n2">
                    =
                    <input type="number" name="resultado" id="result" >


                </div>
            </form>
        </body>
        </html>

It was only necessary to take the s at the end of some of the value, see if you can now.

  • Our not believe that was it, Thanks hehe friend

Browser other questions tagged

You are not signed in. Login or sign up in order to post.