题1
var arr = [34, 54, 87, 99, 12, 23, 44];
var he = 0;
var pjz = 0;
for (var i = 0; i < arr.length; i++) {
he += arr[i];
}
pjz=he/arr.length;
console.log('和:' + he);
console.log('平均值:' + pjz);
题2
var arr = [2, 6, 1, 77, 52, 25, 7];
var max = arr[0];
var min = arr[0];
for (var i = 0; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i]
}if (arr[i] < min) {
min = arr[i]
}
}
console.log('最大值:'+max);
console.log('最小值:'+min);
题3
var arr = ['red', 'green', 'blue', 'pink'];
var newarr=[];
var a = '';
for (var i = 0; i < arr.length; i++) {
newarr[newarr.length]=arr[i]+a;
}
console.log(newarr);
题4
var arr = ['red', 'green', 'blue', 'pink'];
var newarr = [];
var a = '|';
for (var i = 0; i < arr.length; i++) {
newarr[newarr.length]=arr[i]+a;
}
console.log(arr);
题5
var arr = [];
for (var i = 1; i <= 10; i++) {
arr += i + ' ';
}
console.log(arr);
题6
var arr = [];
for (var i = 39; i <= 47; i++) {
arr+=i+' ';
}
console.log(arr);
题7
var arr=[2,0,6,1,77,0,52,0,25,7];
var newarr=[];
for(var i=0;i<arr.length;i++){
if(arr[i]>=10){
newarr[newarr.length]=arr[i]
}
}
console.log(newarr);
题8
var arr=[2,0,6,1,77,0,52,0,25,7];
var newarr=[];
for(var i=0;i<arr.length;i++){
if(arr[i]!=0){
newarr[newarr.length]=arr[i]
}
}
console.log(newarr);
题9
var arr = ['a', 'b', 'c', 'd', 'e'];
var newarr=[];
for (var i = 0; i < arr.length; i++) {
newarr[newarr.length]=arr[arr.length-1-i]
}
console.log(newarr);
题10
var arr = [2, 0, 6, 12, 77, 36, 52, 24, 7];
var he = 0;
for (var i = 0; i < arr.length; i++) {
if (arr[i] % 2 == 0 && arr[i] % 3 == 0) {
he += arr[i]
}
}
console.log('和:'+he);
题11
var arr=[1,2,3,4,,,3,45,,65,'abc'];
var newarr=[];
for(var i=0;i<arr.length;i++){
if(arr[i]!=undefined){
newarr[newarr.length]=arr[i]
}
}
console.log(newarr);
题12
var arr = [2, 4, 6, 8, 10];
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < arr.length; j++) {
if (arr[j + 1] > arr[j]) {
var kong = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = kong;
}
}
}
console.log(arr);