zoukankan      html  css  js  c++  java
  • 入门-2

    优先使用//注释

    二元运算符前后各加一个空格,提高程序的可读性

     javascript会自动进行类型的转换

    ch4_6.html

    <!DOCTYPE html>
    <html>
    <head>
        <title>Pringting Multiple Lines</title>
        <script type="text/javascript">
            <!--
            var firstNumber;
            var secondNumber;
            var num1;
            var num2;
            var sum;
    
            firstNumber = window.prompt("Enter the first number:");
            num1 = parseInt(firstNumber);
    
            secondNumber = window.prompt("Enter the second number:");
            num2 = parseInt(secondNumber);
    
            sum = num1 + num2;
    
            document.writeln("<h1>The sum is " + sum + "</h1>")
    
    
            //-->
        </script>
    </head>
    <body>
    <p>please refresh or reload this script again!</p>
    </body>
    </html>

    ch4_7.html

    <!DOCTYPE html>
    <html>
    <head>
        <title>Pringting Multiple Lines</title>
        <script type="text/javascript">
            <!--
            var name;
            var now = new Date();
            var hour = now.getHours();
    
            name = window.prompt("Enter your name:");
    
            if(hour<12)
                document.write("<h1>Good morning!");
    
            if(hour >=12)
            {
                hour = hour - 12;
    
                if( hour > 6 )
                    document.write("<h1>Good afternoon!");
                else
                    document.write("<h1>Good evening!");
            }
    
            document.writeln( name + ", welcome to javascript programming!</h1>");
            //-->
        </script>
    </head>
    <body>
    <p>please refresh or reload this script again!</p>
    </body>
    </html>

    www.deitel.com/javascript   Deitel公司的javascript资源中心

    ch4_8.html

    <!DOCTYPE html>
    <html>
    <head>
        <title>Pringting Multiple Lines</title>
        <script type="text/javascript">
            <!--
            var total;
            var gradeCounter;
            var grade;
            var gradeValue;
            var average;
    
            total = 0;
    
            gradeCounter = 1;
    
            while( gradeCounter <= 10 )
            {
                grade = window.prompt("Enter the grade:");
    
                gradeValue = parseInt( grade );
    
                total = total + gradeValue;
    
                gradeCounter = gradeCounter + 1;
            }
    
            average = total / 10;
    
            document.writeln("<h1>Class average is " + average + "</h1>");
            //-->
        </script>
    </head>
    <body>
    <p>please refresh or reload this script again!</p>
    </body>
    </html>

    ch4_9.html

    <!DOCTYPE html>
    <html>
    <head>
        <title>Pringting Multiple Lines</title>
        <script type="text/javascript">
            <!--
            var total;
            var gradeCounter;
            var grade;
            var gradeValue;
            var average;
    
            total = 0;
    
            gradeCounter = 0;
    
            grade = window.prompt("Enter the grade:(-1 to quit)","0");
            gradeValue = parseInt( grade );
    
            while( gradeValue != -1 )
            {
                grade = window.prompt("Enter the grade:(-1 to quit)","0");
    
                gradeValue = parseInt( grade );
    
                total = total + gradeValue;
    
                gradeCounter = gradeCounter + 1;
            }
    
            if( gradeCounter != 0 )
            {
                average = total / gradeCounter;
    
                document.writeln("<h1>Class average is " + average + "</h1>");
            }
            else
                document.writeln("<p>No grades were entered.</p>");
            //-->
        </script>
    </head>
    <body>
    <p>please refresh or reload this script again!</p>
    </body>
    </html>

    ch4_10.html

    <!DOCTYPE html>
    <html>
    <head>
        <title>Pringting Multiple Lines</title>
        <script type="text/javascript">
            <!--
            var passes = 0;
            var failures = 0;
            var student = 1;
            var result;
    
            while( student <= 10 )
            {
                result = window.prompt("Enter result(1=pass,0=fail)","0");
    
                if( result == "1" )
                    passes = passes + 1;
                else
                    failures = failures + 1;
    
                student = student + 1;
            }
    
            document.writeln("<h1>Examination results:</h1>");
            document.writeln("Pass: " + passes + "</br>Fail: " + failures );
    
            if( passes > 8 )
            document.writeln("</br>Raised Tuition");
    
    
            //-->
        </script>
    </head>
    <body>
    <p>please refresh or reload this script again!</p>
    </body>
    </html>

    ch4_11.html

    <!DOCTYPE html>
    <html>
    <head>
        <title>Pringting Multiple Lines</title>
        <script type="text/javascript">
            <!--
            var c;
    
            c = 5;
    
            document.writeln("<h3>Postcrement Demo</h3>");
            document.writeln(c);
            document.writeln( "</br>" + (c++) );
            document.writeln( "</br>" +  c );
    
            c = 5;
    
            document.writeln("<h3>precrement Demo</h3>");
            document.writeln(c);
            document.writeln( "</br>" + (++c) );
            document.writeln(  "</br>" + c );
            //-->
        </script>
    </head>
    <body>
    <p>please refresh or reload this script again!</p>
    </body>
    </html>
  • 相关阅读:
    winform把所有dll打包成一个exe
    Windows10+Python3下安装NumPy+SciPy+Matplotlib
    Windows10+Python3+BeautifulSoup4 安装
    解决:无法在发送 HTTP 标头之后进行重定向。 跟踪信息: 在 System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent) 在 System.Web.Mvc.Async.AsyncControllerActionInvoker.<>……
    "请求被中止: 未能创建 SSL/TLS 安全通道"解决办法
    被“1”和“l”给坑了
    谁把我的代码覆盖了
    jQueryUI datepicker 报错: TypeError: inst is undefined
    VS 附加不上w3wp.exe
    MySQL性能调优与架构设计——第 18 章 高可用设计之 MySQL 监控
  • 原文地址:https://www.cnblogs.com/tmmuyb/p/8094088.html
Copyright © 2011-2022 走看看