0

In the first question, I am trying to say how can I add new value with the previous equation answer for example 2 + 2 = 4 then 4 + 3 = 7. In the second question, I am trying to say how can I replace eval value with new value If I want to do a new calculation for example 2 + 5 = 7 then I want to do a new calculation for example 7 replace with 5 + 8 = 13.

<input type="text" class="input">
    <button class="oprator" id="butn4">4</button>
    <button class="oprator" id="butn6">6</button>
    <button id="butnplus">+</button>
    <button id="equal">=</button>





var evaluated = false;
        $(".oprator").click(function () {
        const val = evaluated ? $(this).text() : ($(".input").val() + $(this).text())
        $(".input").val(val)
        evaluated = false;


        $("#butnplus").click(function () {
            $(".input").val($(".input").val() + $("#butnplus").text())
        });
        $("#equal").click(function () {
            $(".input").val((eval($(".input").val())))
            evaluated = true;
        });

0 Answers0