SOURCE

/*
let arr = ['a','b','c','d','e'];
for (let i = 0; i < arr.length; i++) {
    console.log (arr[i])
}
*/
/*
let arr = [1,2,3,4,5,6,7,8,9,10];
let sum = 0;
let average = 0;
for (let i = 0; i < arr.length; i++) {
sum = sum + arr[i];
}
average = sum / arr.length;
console.log (sum);
console.log (average);
*/
/*
let arr = [2,6,1,77,52,25,20];
let max = 2;
for (let i = 0; i < arr.length; i++) {
    if (arr[i] > max) {
        max = arr[i]
    }
}
console.log (max);
*/
/*
let arr = ['red','green','yellow','blue'];
let str = '';
let sep = '&';
for (let i = 0; i < arr.length; i++) {
    str = str + arr[i] + sep;
}
console.log(str)
*/
/*
let arr = ['red','green','yellow','blue'];
arr.length = 6;
console.log(arr)
*/
/*
let arr = ['red','green','yellow','blue'];
arr[6] = 'pink';
console.log(arr);
*/
/*
let arr1 = [2,0,6,1,77,0,52,0,25,7];
let arr2 = [];
for (let i = 0; i <= arr1.length; i++) {
    if (arr1[i] >= 10) {
        arr2[arr2.length] = arr1[i];
    }
}
console.log(arr2);
*/
/*
let arr1 = [2,0,6,1,77,0,52,0,25,7];
let arr2 = [];
for (i = 0; i < arr1.length; i++) {
    if (arr1[i] !== 0) {
arr2[arr2.length] = arr1[i];
    }
}
console.log(arr2);
*/
/*
let arr1 = ['red','orange','blue','yellow','pink'];
let arr2 = [];
for (i = arr1.length - 1; i >= 0; i--) {
arr2[arr2.length] = arr1[i];
}
console.log(arr2);
*/
/*
let arr = [4,1,2,3,5];
for (let i = 0; i <= arr.length; i++) {
    for (let j = 0; j <= arr.length - i -1; j++) {
        if (arr[j] < arr[j + 1]) {
            let temp = arr[j];
            arr[j] = arr[j + 1];
            arr[j + 1] = temp;
        }
    }
} 
console.log(arr);
*/
/*
function getSum() {
    let sum = 0;
for (let i = 1; i <= 100; i++) {
    sum = sum + i;
}
console.log (sum);
}
getSum();
*/
/*
function getSum(num1,num2) {
    let sum = 0;
for (let i = num1; i <= num2; i++) {
    sum = sum + i;
}
console.log (sum);
}
getSum(1,100);
*/
/*
function getSum(num1,num2) {
    console.log (num1 + num2)
}
getSum(100,2)
getSum(100,3)
*/
/*
function getSum (start,end) {
    let sum = 0;
    for (let i = start; i <= end; i++) {
        sum += i;
    }
    console.log(sum);
}
getSum(1,100);
getSum(50,100);
getSum(1,10);
*/
/*
function getSum(num1,num2) {
    console.log (num1 + num2)
}
getSum(1,1);
getSum(1,1,1);
getSum(1);
*/
/*
function getSum(num1,num2) {
    return num1 + num2;
}
console.log (getSum(1,1));
*/
/*
function getMax(num1,num2) {
    let max;
    if (num1 > num2) {
    max = num1;
    } else {
        max = num2;
    }
    return max;
}
console.log (getMax(200,2));
*/
/*
function getMax(num1,num2) {
    if (num1 > num2) {
    return num1;
    } else {
    return num2;
    }
}
console.log (getMax(100,2));
*/
/*
function getMax(num1,num2) {
    return num1 > num2 ? num1 : num2;
}
console.log (getMax(3,2));
*/

/* 利用function求一个array里面的最大值:

function getArrMax(arr) {
    let max = arr[0];
    for (let i = 1; i <= arr.length; i++) {
        if (arr[i] > max) {
            max = arr[i];
        }       
    }
    return max;
}
let result = getArrMax([5,2,99,101,67,77]);
console.log (result);
*/


function caculation() {
    let indicate = true;
    while (true) {
        let input = prompt('请输入您要进行的运算:' + '\n' + '1.加法' + '\n' + '2.减法' + '\n' + '3.乘法' + '\n' + '4.除法' + '\n' + '5.退出');
        switch (input) {
            case '1':
                num1 = parseFloat(prompt('请输入第一个数字:'));
                num2 = parseFloat(prompt('请输入第二个数字:'));
                alert('运算结果为' + 'num1 + num2');
                break;
            case '2':
                num1 = parseFloat(prompt('请输入第一个数字:'));
                num2 = parseFloat(prompt('请输入第二个数字:'));
                alert('运算结果为' + 'num1 - num2');
                break;
            case '3':
                num1 = parseFloat(prompt('请输入第一个数字:'));
                num2 = parseFloat(prompt('请输入第二个数字:'));
                alert('运算结果为' + 'num1 * num2');
                break;
            case '4':
                num1 = parseFloat(prompt('请输入第一个数字:'));
                num2 = parseFloat(prompt('请输入第二个数字:'));
                alert('运算结果为' + 'num1 / num2');
                break;
            case '5':
                indicate = false;              
                break;
        }
    }
}
caculation();
console 命令行工具 X clear

                    
>
console