for (var i = 0; i < operator.length; i++) {
operator[i].addEventListener('click', function() {
if (this.id == "clear") {
printHistory("");
printOutput("");
} else if (this.id == "backspace") {
var output = reverseNumberFormat(getOutput()).toString();
if (output) {
//if output has a value
output = output.substr(0, output.length-1);
printOutput(output);
}
} else {
var output = getOutput();
var history = getHistory();
if (output == "" && history != "") {
if (isNaN(history[history.length-1])) {
history = history.substr(0, history.length-1);
}
}
if (output != "" || history != "") {
output = output == ""?output: reverseNumberFormat(output);
history = history+output;
if (this.id == "=") {
var result = eval(history);
printOutput(result);
printHistory("");
} else {
history = history+this.id;
printHistory(history);
printOutput("");
}
}
}
});
}
我试图让该十进制按钮弹出我的计算器,尝试添加一个if语句,该语句检查输出是否为十进制,这是行不通的。单击按钮后,我一直得到NaN作为输出,