2
The doubt is exactly how I can "print" a value from within my Javascript code so I can track if 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 solved tests one of the modules in order to verify the calculated value. But then came another problem that is not knowing how I can "print" this value in the code so I can view in my browser.
Impostoderenda
<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>
If it is only for debug purposes you can use console.log(Nameavailablehere) in the parts of the code where you want to track the value, then to view just press F12 with your website running and it will appear in the "console" section of the window that opens. Another alternative is to press again F12 and put a line Debugger; in your code to stop your program, there with F10 you can go running row by row viewing as the value of the variable you want to track changes in the window that F12 opened, in this case just put the mouse on top of the variable where it appears in the code.
– Paz