Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72388

javascript calculator (how i make the first click does not accept operation)

$
0
0

how I make the first click does not accept operation and return "0"

Here is my function

$(document).ready(function(){
    $('button').on('click', function(){
        var previosValue = $('.viewer').text();
        var val = $(this).text();
        if(val == "="){
            var op = eval($('.viewer').text());
            $('.viewer').text(op);
        } else if(val == "AC"){
            $('.viewer').text("0");
        } else {
            if($('.viewer').text() == "0"){
                $('.viewer').text(val);
            } else {
                $('.viewer').text(previosValue + val);
            }
        }
    });
});

there is the full code on codepen


Viewing all articles
Browse latest Browse all 72388

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>