how to use if else in javascript

55 views Asked by At

In above code i cant display per if i give any condition like if i can i achieve this and at the end of this code not only if statement bt also any document.write function is not working.

<body>
    <script>
    var math = Math.floor(window.prompt("Enter Math Marks"));
    document.write("Math Marks :"+math);
    var eng = Math.floor(window.prompt("Enter English Marks"));
    document.write("</br>English Marks : "+eng);
    var php = Math.floor(window.prompt("Enter PHP Marks"));
    document.write("</br> PHP Marks :"+php);
    var java = Math.floor(window.prompt("Enter JAVA Marks"));
    document.write("</br> JAVA Marks : "+java);
    var csharp = Math.floor(window.prompt("Enter C Sharp Marks"));
    document.write("</br> C Sharp Marks : "+csharp);
        var total = Math.floor(500);
        var obt  = Math.floor(math + eng + php + java +csharp);
        document.write("<br>"+obt);
    var per = Math.floor(document.write("<br>Percentage" (obt * 100)/total));
    document.write("nothing is dispaling");

        if(per<40){
            document.write("Fail");
        }

    </script>

</body>
</html>
1

There are 1 answers

0
Alex On
<script type="text/javascript">
<!--
var age = 20;
if( age > 18 ){
   document.write("<b>Qualifies for driving</b>");
}
//-->
</script>

More exmples:

<script type="text/javascript">
<!--
var age = 15;
if( age > 18 ){
   document.write("<b>Qualifies for driving</b>");
}else{
   document.write("<b>Does not qualify for driving</b>");
}
//-->
</script>