lundi 13 août 2018

cant find Bug in following Javascript code?

<!DOCTYPE>
<html>
<head>
    <script>
        var sin0=0;
        var sin30=1/2;
        var sin45=Math.sqrt(1)/2;
        var sin60=Math.sqrt(3)/2;
        var sin90=1;
        var cos0=1;
        var cos30=Math.sqrt(3)/2;
        var cos45=Math.sqrt(1)/2;
        var cos60=1/2;
        var cos90=0;
        var tan0=0
        var tan30=1/Math.sqrt(3);
        var tan45=1;
        var tan60=Math.sqrt(3);
        var sec0=1;
        var sec30=2/Math.sqrt(3);
        var sec45=Math.sqrt(2);
        var sec60=2;
        var cosec30=2;
        var cosec45=Math.sqrt(2);
        var cosec60=2/Math.sqrt(3);
        var cosec90=1;
        var cot30=Math.sqrt(3);
        var cot45=1;
        var cot60=1/Math.sqrt(3);
        var cot90=0;
        var p=document.getElementById("p").value;
        var b=document.getElementById("b").value;
        var h=document.getElementById("h").value;
        var l=document.getElementById("l").value;

        function func(){

        if(p==""&&b==""){

            if(l==0){
            var pe=sin0*h;
            }   

            if(l==30){
            var pe=sin30*h;
            }

            if(l==45){
            var pe=sin45*h;
            }

            if(l==60){
            var pe=sin60*h;
            }

            if(l==90){
            var pe=sin490*h;
            }
        }

        if(h==""&&b==""){

            if(l==0){
            alert("Not Defined");
            }

            if(l==30){
            var hy=cosec30*p;
            }

            if(l==45){
            var hy=cosec45*p;
            }

            if(l==60){
            var hy=cosec60*p;
            }

            if(l==90){
            var hy=cosec90*p;
            }

        }

        if(h==""&&p==""){

            if(l==0){
            var hy=sec0*b;
            }

            if(l==30){
            var hy=sec30*b;
            }

            if(l==45){
            var hy=sec45*b;
            }

            if(l==60){
            var hy=sec60*b;
            }

            if(l==90){
            alert("Not Defined");
            }

        }

        alert(pe);

        }
    </script>
</head>
<body>
    <p>
    You need to have at least 1 Angle of the 'Triangle formed' and at least 1 side 's length (in metres). <br>
    To apply Trigonometry.<br><br>
    Which side do you have? <br>
    </p>
    <label>Perpendicular</label>&nbsp;&nbsp;<input id="p" type="number"/> &nbsp;&nbsp;&nbsp;&nbsp;
    <label>Base</label>&nbsp;&nbsp;<input id="b" type="number"/>&nbsp;&nbsp;&nbsp;&nbsp; 
    <label>Hypotenuse</label>&nbsp;&nbsp;<input id="h" type="number"/><br><br>
    <label>Measure of Angle you have</label>&nbsp;&nbsp;<input type="number" id="l">
    <input type="button" value="Solve" onclick="func()"/>
</body>
</html>

I've created this code for "Applications of Trigonometry". I think I've every variable well defined, but Every time, I run this , it throws 'undefined' .

I'M NEW TO JS !

You can enter only 0,30,45,60 and 90 in "Angle" input field. And fill only one of fields out of 'Perpendicular' , 'Base' , and 'Hypotenuse'.




Aucun commentaire:

Enregistrer un commentaire