equal 按钮只返回 0

equil button is only returning 0

我正在为我的 class 构建一个计算器我已经走到这一步但是每当我按下等于它时 returns 0 而不是答案我不知道在哪里或什么改变......

$(document).ready(function() {
    var expression = "";
    function appendChar(char) {
    expression += char;
    var eval;
    try {
     result = eval(equals);


    $("#calculation").text(expression + " = " + result);
    } catch (e) {

    $("#calculation").text(expression);



    }
}



    $(".digit, .operator").click(function()    {
        appendChar($(this).text());
    });

    $(".clear").click(function()    {
        expression = "";
        $("#calculation").text("0");
    });

    $(".equals").click(function()    {

         expression = "";
        $("#calculation").text("0");

    });

});

当您打电话时:

$("#calculation").text("0");

您犯了一个错误,因为“.text("0")”将您的结果设置为“0”。 相反,您必须将结果放在那里。

$("#calculation").text(result);