如何在javascript中使用if else

时间:2014-03-14 19:29:40

标签: javascript

在上面的代码中我不能显示每个如果我给出任何条件,如果我能实现这一点 并且在此代码的末尾不仅声明bt还有任何document.write函数不起作用。

<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 个答案:

答案 0 :(得分:1)

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

更多例子:

<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>