The function is not returning the variable in html

Asked

Viewed 29 times

-1

<script>function calcular() {

        var d1 = document.getElementById('diametro1').value;
        var d2 = document.getElementById('diametro2').value;
        var w1 = 42,305 / Math.sqrt(d1) ;
        var w2 = 76,63 / Math.sqrt(d2) ;;

        document.getElementById('w1').innerHTML = "Resultado: "+parseFloat(w1.toFixed(8));
        document.getElementById('w2').innerHTML = "Resultado: "+parseFloat(w2.toFixed(8));

    }
</script>
  • Javascript numbers have no comma.

1 answer

2

There are at least two syntax errors in the following lines:

var w1 = 42,305 / Math.sqrt(d1) ;
var w2 = 76,63 / Math.sqrt(d2) ;;
  • First: no comma is used , to identify numbers of the type float in JavaScript. For values of the type float we use point .. If the number is integer, leave no comma or dot, even if it is greater than 999
  • Second: do not use the semicolon sign without need, as in your code: ;;

Browser other questions tagged

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