//全局变量、局部变量
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/>");
//表达式调用
function add(i,j) {
var one = i + j;
return one;
}
var a = add(1,2) + 3;
document.write(a+"<br/>");
document.write("--------------------------------<br/>");
//判断是否是闰年
function isLeapYear(year){
if((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)){
document.write(year+" is an leap year "+ "<br/>");
}
else{
document.write(year+" is not a leap year "+ "<br/>");
}
}
isLeapYear(2020);
isLeapYear(2000);
isLeapYear(2001);
document.write("--------------------------------<br/>");
//求出4个数中的最大值
function maxnum(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("4个数中的最大值是:" + maxnum(1,7,11,10)+"<br/>");
document.write("--------------------------------<br/>");
//定义两个函数,分别求出任意五个数中的最大值和最小值
function maxNum(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;
}
function minNum(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个数中的最大值是:" + maxNum(5,3,8,2,7)+"<br/>");
document.write("5个数中的最小值是:" + minNum(5,3,8,2,7)+"<br/>");
console