和差积商不需要选择,会直接输出四个结果,商保留两位小数
function math() {
var l = arguments.length;
var sum = arguments[0];//和
var difference = arguments[0];//差
var product = arguments[0];//积
var label = arguments[0];//商
for (var i = 1; i < l; i++) {
sum += Number(arguments[i]);
difference -= Number(arguments[i]);
product *= Number(arguments[i]);
label /= arguments[i];
}
return [sum, difference, product, label];
// label=label.toFixed(6);
}
var num = math(1, 2, 3, 4, 5, 6);
console.log("数字的和= "+ num[0]);
console.log("数字的差= "+ num[1]);
console.log("数字的积= "+ num[2]);
console.log("数字的商= " + num[3]);