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/>");
function isLeapYear(year)
{
//判断闰年的条件
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
{
document.write(year + " is a leap year." + "</br>");
}
else
{
document.write(year +" is not a leap year." + "</br>");
}
}
//调用函数
isLeapYear(2000);
isLeapYear(2001);
isLeapYear(2020);
function getMax(a,b,c,d)
{
var maxNum;
maxNum = (a > b) ? a : b;
maxNum = (maxNum > c) ? maxNum : c;
maxNum = (maxNum > d) ? maxNum : d;
return maxNum;
}
document.write("4个数中的最大值为:" + getMax(4,1,12,30));
console