js计算器小练习
function calculator(){
var operator =arguments[arguments.length - 1];
if ( operator == '+'){
for (var i = 1, i<arguments.leng - 1; i++) {
arguments[0] +=arguments[i];
};
console.log(arguments[0]);
}else if ( operator == '-'){
for (var i = 1, i <arguments.length - 1; i++){
arguments[0] -=arguments[i];
};
console.log(arguments[0]);
} else if ( operator == '*'){
for (var i = 1, i<arguments.length - 1;i++){
arguments[0] *=arguments[i];
};
console.log(arguments[0]);
} else if ( operator == '/'){
for (var i =1,i<arguments.length -1;i++){
arguments[0]/=arguments[i];
};
console.log(arguments[0]);
}
}
calculator(1,2,3,4,'+');
calculator(80,20,13,12,'-');
calculator(1,2,3,4,5,'*');
calculator(100,2,5,2,'/');