SOURCE

function run(b)
{
    if(b%4==0&&b%100!=0)
    {
        document.write(b+"是闰年<br/>");
    }
    else if(b%400==0)
    {
        document.write(b+"是闰年<br/>");
    }
    else
    {
        document.write(b+"不是闰年<br/>");
    }
}
run (2020);
run (2000);
run (2001);


function op (c,d,e,f)
{
    var max=0;
    max=c>d?c:d;
    max=e>max?e:max;
    max=f>max?e:max;
    document.write("最大值为:"+max+"<br/>");

}
var c=56,d=43,e=77,f=33;
op(c,d,e,f);




function writeDocument(variable){
document.write(variable + "<br/>");
}

document.write("数组创建----------------------------------" + "<br/>")
var arr=["HTML","CSS","JavaScript","jQuery","Vue.js"];
document.write(arr + "<br/>");

document.write("数组下标取值----------------------------------" + "<br/>")
document.write(arr[2] + "<br/>");

document.write(arr + "<br/>");

arr[4]="React.js";

document.write(arr + "<br/>");

arr[5]="Vue.js";

document.write(arr + "<br/>");

arr[8]="Angular.js";

document.write(arr + "<br/>");

document.write("获取数组长度----------------------------------" + "<br/>")
var arr1=[];
var arr2=[1,2,3,4,5,6];
document.write(arr1.length + "<br/>");
document.write(arr2.length + "<br/>");

document.write("获取数组某一段----------------------------------" + "<br/>")
document.write(arr.slice(1,3) + "<br/>");

document.write("往数组头添加元素----------------------------------" + "<br/>")
var arr3=["JavaScript","jQuery"];
arr3.unshift("Html","css");
document.write(arr3 + "<br/>");

document.write("往数组尾添加元素----------------------------------" + "<br/>")
arr3.push("Html","css");
document.write(arr3 + "<br/>");

document.write("删除数组的第一个元素----------------------------------" + "<br/>")
var arr4=["Html","css","JavaScript","jQuery"];
arr4.shift();
document.write(arr4 + "<br/>");

document.write("删除数组的最后一个元素----------------------------------" + "<br/>")
arr4.pop();
document.write(arr4 + "<br/>");

document.write("对字母字符串数组按升序排序----------------------------------" + "<br/>")
document.write(arr.sort() + "<br/>");

var numArr = [3,6,9,1,4,11];
document.write("排序前:" + numArr + "<br/>");
function upcompare(l,r){
if(l>r){
return 1;
}
if(l==r){
return 0;
}
if(l<r){
return -1;
}
}
numArr.sort(upcompare);
document.write("升序排序后:" + numArr + "<br/>");

function downcompare(l,r){
if(l>r){
return -1;
}
if(l==r){
return 0;
}
if(l<r){
return 1;
}
}
numArr.sort(downcompare);
document.write("降序排序后:" + numArr + "<br/>");

document.write("反转数组:" +numArr.reverse() + "<br/>");
document.write("默认Join数组:" +numArr.join() + "<br/>");
document.write("默认Join数组:" +"<br/>");
document.write("默认Join数组:" +numArr.join("-") + "<br/>");
document.write("默认Join数组:" +numArr.join("><") + "<br/>");

var str1="绿叶学习网";
var str2=str1.split("").join("><");
var arr = str2.split("");
arr.unshift("<");
arr.push(">");
var result=arr.join("");
document.write(result);


function writeDocument(variable) {
    document.write(variable + "<br/>");
} 

writeDocument("定义时间对象-------------"); 
var oToday = new Date();
writeDocument("获取年,月,日,时,分,秒,毫秒-------------");
 writeDocument("年:"+oToday.getFullYear());
  writeDocument("月:"+oToday.getMonth());
   writeDocument("日:"+oToday.getDate());
    writeDocument("时:"+oToday.getHours());
    writeDocument("分:"+oToday.getMinutes()); 
    writeDocument("秒:"+oToday.getSeconds());
writeDocument("毫秒: "+oToday.getMilliseconds());

writeDocument("设置年,月,日,时,分,秒,毫秒-------------");
var oDate = new Date(2019);

oDate.setFullYear(2020);
writeDocument("年:  "+oDate.getFullYear());
oDate.setMonth(5);
writeDocument("月:  "+(oDate.getMonth()+1));
oDate.setDate(1);
writeDocument("日:  "+oDate.getDate()); 
oDate.setHours(16);
writeDocument("时:  "+oDate.getHours());
oDate.setMinutes(58);
writeDocument("分:  "+oDate.getMinutes()); 
oDate.setSeconds(59);
writeDocument("秒:  "+oDate.getSeconds()); 
oDate.setMilliseconds(999);
writeDocument("毫秒:  "+oDate.getMilliseconds());

var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]; 

writeDocument("今天是"+weeks[oToday.getDay()]);
var oPrintDate = new Date(2019,5,1,15,59,59,999);
writeDocument("打印2019年6月1日 星期六 15:59:59:999-------------------");
console 命令行工具 X clear

                    
>
console