下午主要讲了数组
数组文档 array
数组的定义:一系列同数据类型的数据集合 比如: 1,2,3,4,5 "a","b","c","d"
var aa = new Array();
aa[0] = 1;
aa[1] = 2;
aa[2] = 3;
aa[3] = 4;
aa[4] = 5;
console.log(aa);
console.log("aa");
console.log(123);
常用方法:
length(长度)
push(添加元素)
join(数组转字符串)
concat(连接数组)
sort(排序)
var aa = ["ccc"];
for (var i = 0; i<aa.length;i++){
document.write(aa[i]);
}
输入 语文,数学,英语成绩 求 最高分,最低分,平均分
var score = []
for(var i = 0; i<3;i++){
var num = prompt('请输入成绩');
score.push(num);
document.write("第" +(i+1) + "门成绩是" + num +"<br>");
}
var max = score[0];
var min = score[1];
var sum = 0;
for(var i = 0; i<score.length;i++){
if(max < score[i]){
max = score[i];
}
if(min>score[i]){
min = score[i];
}
sum = +sum + +score[i];
}
document.write("最高分:" + max + "最低分:" + min + "平均分:" +(sum/score.length))