How can I print a variable from within the JavaScript script?

1

The question is exactly how do I "start" a value from within my JavaScript code so I can track whether the variable has the correct value.

I'm learning JavaScript in college and was writing a paper that takes the code down. However after some errors I decided to test one of the modules in order to verify the calculated value. But there came another problem that is not knowing how I can "start" this value in the code so that I can view in my browser.

             Income tax                        

        <h1>Cálculo do Imposto de Renda</h1>

        <br>
        Contribuição previdenciaria: <input type="text" name="contribuicao" id="contribuicaoId">
        <br>
        Despesas medicas:<input type="text" name="despesas" id="despesasId">
        <br>
        Número de dependentes: <input type="text" name="dependentes" id="dependentesId">
        <br>        
        Enviar: <input type="submit" name="enviar" onclick="deducao()">


        <script language="JavaScript">
        function deducao(){
                var dedu;
                var contribuicao=parseInt(getElementById("contribuicaoId").value,10);
                var despesas=parseInt(getElementById("despesasId").value,10);
                var dependentes=parseInt(getElementById("dependentesId").value,10);

            dedu=contribuicao+despesas+dependentes*3050;
            document.write("Resposta:" +dedu);
    }

        </script>
    </body>
</html>
    
asked by anonymous 17.10.2018 / 19:00

2 answers

2

Use the console.log() function to display its value in the browser console. Press F12 in the browser, then click the console tab and the value will appear in the browser console.

Example usage:

var valor = 10;
console.log('O valor é: ' + valor);
  

Browser Console Sample Image

     

Add in the points in your code that you need to review and follow through the browser console.

I hope I have helped.

    
17.10.2018 / 19:10
1

Use console.log() , this will start in the browser console that can be accessed using F12 (look for the 'Console' tab)

    
17.10.2018 / 19:10