SOURCE

//全局变量、局部变量
var globalVariable1 = 0;

function test1() {
    document.write(localVariable1+ "<br/>");
    var localVariable1 = 2;
    //打印globalVariable1
    document.write(globalVariable1 + "<br/>");

    //打印localVariable1
    document.write(localVariable1+ "<br/>");
}

//打印localVariable1
//document.write(localVariable1);

//打印globalVariable2
document.write(globalVariable2 + "<br/>");

test1();

var globalVariable2 = 1;

function test2() {
    var localVariable2 = 3;

    //打印localVariable1
    //document.write(localVariable1 + "<br/>");

}
test2();

//打印localVariable2
//document.write(localVariable2 + "<br/>");
//打印globalVariable1
document.write(globalVariable1 + "<br/>"); 
document.write("--------------------------------<br/>");

//document.write("------------------------------<br/>"); 
//表达式的调用
document.write("---表达式的调用---<br/>"); 
function add(a,b)
{
    var c;
    c=a+b;
    return c;
}
//调用函数
var n = add(1,2)+222; 
document.write(n+"<br/>");



//判断是否闰年
document.write("---判断是否是闰年---<br/>"); 
function isLeapYear(year)
{
    if(year%4==0&&year%100!=0){
        document.write(year+" is an leap year"+"<br/>");
    }
    else if (year%400==0)
	{  
		document.write(year+" is a leap year"+"<br/>");
    }  
    else
	{  
       document.write(year+" is not a leap year"+"<br/>");
    }
}

isLeapYear(2020); 
isLeapYear(2000); 
isLeapYear(2001);

/*
//判断闰年2
document.write("---判断是否是闰年---<br/>"); 
function isLeapYear(year)
{
    var result = false;

    if(year%4==0&&year%100!=0){
        result = true;
    }
    else if (year%400==0)
	{  
		result = true;
    }  
   if(result)
	{  
       document.write(year+" is a leap year"+"<br/>");
    }
    else{
        document.write(year+" is not a leap year"+"<br/>");
    }
}
isLeapYear(2020); 
isLeapYear(2000); 
isLeapYear(2001);
*/

document.write("----------------------------------<br/>");
document.write("---求出4个数中的最大值---<br/>"); 
//求出4个数中的最大值
function max(a,b,c,d){
    var max=a;
    if(b>max){
        max=b;
    }
    if(c>max){
        max=c;
    }
    if(d>max){
        max=d;
    }
    return max;  
}

document.write("最大值是:" + max(10,5,6,12)+"<br/>");

document.write("----------------------------------<br/>");

//定义两个函数,分别求出任意五个数中的最大值和最小值
document.write("---定义两个函数,分别求出任意五个数中的最大值和最小值---<br/>"); 
function max1(a,b,c,d,e){
    var max=a;
    if(b>max){
        max=b;
    }
    if(c>max){
        max=c;
    }
    if(d>max){
        max=d;
    }
    if(e>max){
        max=e;
    }   
    return max;  
}
document.write("5个数中的最大值是:" + max1(10,8,18,3,6)+"<br/>");
function min(f,g,h,i,j){
    var min=f;
    if(g<min){
        min=g;
    }
    if(h<min){
        min=h;
    }
    if(i<min){
        min=i;
    }
    if(j<min){
        min=j;
    }   
    return min;  
}
document.write("5个数中的最小值是:" + min(10,8,18,3,6)+"<br/>");












console 命令行工具 X clear

                    
>
console