function writeDocument(variable) {
document.write(variable + "<br/>");
}
writeDocument("数组创建----------------------------------");
var arr=["HTML","CSS","JavaScript","jQuery","Vue.js"];
writeDocument(arr);
writeDocument("数组下标取值------------------------------");
writeDocument(arr[2]);
writeDocument("数组赋值---------------------------------");
arr[4]="React.js";
writeDocument(arr);
arr[5]="Vue.js";
writeDocument(arr);
arr[8]="Angular.js";
writeDocument(arr);
//以上是week4内容
writeDocument("获取数组的长度----------------------------");
writeDocument("数组的长度为"+arr.length);
writeDocument("获取数组的1-2号元素----------------------------");
writeDocument("往数组头添加元素----------------------------");
writeDocument("往数组尾部添加元素----------------------------");
writeDocument("删除数组的第一个元素----------------------------");
writeDocument("删除元素:"+arr.shift());
writeDocument("删除数组的最后一个元素----------------------------");
writeDocument("删除元素:"+arr.pop());
writeDocument("对字符串数组进行升序的排序----------------------------");
function upCompare(left,right){
if(left-right>0){
return 1;
}
if(left-right==0){
return 0;
}
if(left-right<0){
return -1;
}
}
function downCompare(left, right) {
if (left - right > 0) {
return -1;
}
if (left - right == 0) {
return 0;
}
if (left - right < 0) {
return 1;
}
}
writeDocument("打印排序前的数字数组"+arr);
writeDocument("打印升序排列后的数组"+arr)
//以上为第一堂课内容
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("年:"+oToday.getFullYear());
oDate.setMonth(5);
writeDocument("月:"+(oToday.getMonth()+1) );
oDate.setMonth(1);
writeDocument("日:"+oToday.getDate());
oDate.setMonth(16);
writeDocument("时:"+oToday.getHours());
oDate.setMonth(58);
writeDocument("分:"+oToday.getMinutes());
oDate.setMonth(59);
writeDocument("秒:"+oToday.getSeconds());
writeDocument("打印2019年6月1日 星期六 15:59:59:999-------------");
var oPrintDate = new Date(2019, 6, 1, 15, 59, 59, 999);
var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
writeDocument("年: "+oPrintDate.getFullYear());
writeDocument("月: "+oPrintDate.getMonth());
writeDocument("日: "+oPrintDate.getDate());
writeDocument("今天是:"+weeks[oPrintDate.getDate()]);
writeDocument("时: "+oPrintDate.getHours());
writeDocument("分: "+oPrintDate.getMinutes());
writeDocument("秒: "+oPrintDate.getSeconds());
writeDocument("毫秒: "+oPrintDate.getMilliseconds());
//数学对象
writeDocument("生成随机验证码----------------------");
function generateVerifyCode(length){
var strValue ="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var code="";
for(var i=0;i<length;++i){
var randomIndex=Math.floor(Math.random()*strValue.length);
code +=strValue.charAt(randomIndex);
}
return code;
}
writeDocument(generateVerifyCode(4));
writeDocument(generateVerifyCode(5));
writeDocument(generateVerifyCode(6));
writeDocument("用Math的方法找出3,9,12,99,45,75中的最大值和最小值--------");
var a = Math.max(3,9,12,99,45,75);
var b = Math.min(3,9,12,99,45,75);
document.write("最大值为:" + a + "<br/>");
document.write("最小值为:" + b+ "<br/>");
writeDocument("随机生成一个颜色值rgb(x,y,z)的函数,其中x标识的是0~255--------");
function getColor() {
var r = Math.floor(Math.random() * 256);
var g = Math.floor(Math.random() * 256);
var b = Math.floor(Math.random() * 256);
var rgb = "rgb(" + r + "," + g + "," + b + ")";
return rgb;
}
writeDocument(getColor());
console