问答详情
源自:5-6 编程练习

仅供参考:

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>Document</title>

</head>

<body>

    

    <script type="text/javascript">

        function compare(a,b){

            if(a==b){

                return a+"和"+b+"相等";

            }else if(a>b){

                return a+"和"+b+"中较大值的值是:"+a

            }else{

                return a+"和"+b+"中较大值的值是:"+b

            }

        }

        document.write(compare(2,2)+'<br>');

        document.write(compare(5,4)+'<br>');

        document.write(compare(6,3)+'<br>');

    </script>

</body>

</html>

输出结果:

http://img.mukewang.com/5de0da370001893d02330080.jpg

提问者:秋之枫华 2019-11-29 16:43

个回答

  • YF_YYDS
    2019-11-30 10:38:54

    !DOCTYPE  HTML>

    <html >

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>函数</title>


    <script type="text/javascript">


    //定义函数

    function compare(x,y){

        max=x>y?x:y;

        return max;

    }




    //函数体,判断两个整数比较的三种情况


     

    //调用函数,实现下面两组数中,返回较大值。

      document.write(" 5 和 4 的较大值是:"+compare(5,4)+"<br>");

      document.write(" 6 和 3 的较大值是:"+compare(6,3) ); 





    </script>

    </head>

    <body>

    </body>

    </html>