cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <section id="calculator">
        <div class="main-area">
            <div id="calc-title">ONLINE CALCULATOR</div>
            <div class="display">
                <!--div id="result">0</div-->
                <input type="text" name="calc-input" id="result" value='0' readonly>
                <!--div id="hints">hints</div-->
            </div>

            <div class="first-row">
                <button class="all-buttons button clear-button" id='ac' onclick="clearAll()">AC</button>
                <button class="all-buttons button clear-button" id='ac' onclick="clearEntry()">CE</button>
                <button class="all-buttons button sign" id='ac' data-sign="/">/</button>
                <button class="all-buttons button sign" id='ac' data-sign="*">X</button>
            </div>
            <div class="second-row">
                <button class="all-buttons button press" id='ac' data-number="7">7</button>
                <button class="all-buttons button press" id='ac' data-number="8">8</button>
                <button class="all-buttons button press" id='ac' data-number="9">9</button>
                <button class="all-buttons button sign" id='ac' data-sign="-">-</button>
            </div>
            <div class="third-row">
                <button class="all-buttons button press" id='ac' data-number="4">4</button>
                <button class="all-buttons button press" id='ac' data-number="5">5</button>
                <button class="all-buttons button press" id='ac' data-number="6">6</button>
                <button class="all-buttons button sign" id='plus' data-sign="+">+</button>
            </div>

            <div class="fourth-row">
                <button class="all-buttons button press" id='ac' data-number="1">1</button>
                <button class="all-buttons button press" id='ac' data-number="2">2</button>
                <button class="all-buttons button press" id='ac' data-number="3">3</button>
                <button class="all-buttons button-result" id='ac' onclick="calc()">=</button>
            </div>
            <div class="fifth-row">
                <button class="all-buttons button-zero press" id='ac' data-number="0">0</button>

                <button class="all-buttons button press" id='ac' data-number=".">.</button>

            </div>




        </div>
        <div class="copyright">
            <p>designed and coded by <a href="http://kamberov.me" target="_blank">Rustam Kamberov</a> </p><br>
            <p>background image by <a href="https://unsplash.com/@thepip?utm_medium=referral&amp;utm_campaign=photographer-credit&amp;utm_content=creditBadge"
                    target="_blank" rel="noopener noreferrer">Francisco Gomes</span></a></p>
        </div>

    </section>

            
          
!
            
              * {
    margin: 0;
    padding: 0;
}

body {
    margin: 0;
    font-family: Courier New, Courier, monospace;
}

#calculator {
    background-image: url('https://source.unsplash.com/kktq8zzmPEo/1600x900');
    background-size: cover;
    background-position: center;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 0 20px;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

.main-area {
    border: #A9A9A9 1px solid;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 300px;
    /*height: 400px;*/
    color: #ffffff;
    background: #35424a;
    border-radius: 20px;
    min-height: 400px;
}

#calc-title {
    padding: 20px 20px;
}

.display {
    font-size: 25px;
    width: 260px;
    height: 30px;
    border-radius: 5px;
    background: #ffffff;
    color: black;
    text-align: right;
    margin-bottom: 10px;
}

#result {
    font-size: 25px;
    width: 260px;
    height: 30px;
    border-radius: 5px;
    background: #ffffff;
    color: black;
    text-align: right;
    margin-bottom: 10px;
}

#hints {
    font-size: 15px;
    color: #D3D3D3;
}

.all-buttons {
    font-size: 15px;
    width: 55px;
    height: 40px;
    text-align: center;
    cursor: pointer;
    outline: none;
    color: #ffffff;
    background-color: #696969;
    border-radius: 5px;
    box-shadow: 0 7px #4d4d4d;
    vertical-align: top;
}

.button {
    margin: 7px 2px;
}

.all-buttons:hover {
    background-color: #4d4d4d;
}

.all-buttons:active {
    background-color: #4d4d4d;
    box-shadow: 0 5px #666;
    transform: translateY(2px);
}

.button-result {
    /*padding: 45px 18px;*/
    height: 95px;
    margin: 7px 2px;
    color: #ffffff;
    background-color: #696969;
    border-radius: 5px;
}

.fifth-row {
    margin-top: -55px;
    margin-left: -69px;
}

.button-zero {
    padding: 10px 60px;
    margin: 7px 2px;
    color: #ffffff;
    background-color: #696969;
    border-radius: 5px;
}

.clear-button {
    background-color: #BD0048;
}

.clear-button:hover {
    background-color: #960039;
}

.clear-button:active {
    background-color: #960039;
    box-shadow: 0 5px #666;
    transform: translateY(2px);
}

.copyright {
    margin-top: 20px;
    text-align: center;
    font-size: 10px;
    color: #ffffff;
}

a {
    text-decoration: none;
    color: silver;
}
            
          
!
            
              var resText = '';

function clearAll() {
    $("#result").val('0');
    resText = '';
}

$('.press').click(function () {
    if ($('#result').val() === '0' ||
        resText.slice(-1) === '+' ||
        resText.slice(-1) === '-' ||
        resText.slice(-1) === '/' ||
        resText.slice(-1) === '*' ||
        resText === '') {

        $('#result').val("");
    }

    var number = $(this).data('number');

    $('#result').val(function () {
        resText += number;
        console.log(resText);
        return this.value + number;
    });
});

$('.sign').click(function () {
    if ($('#result').val().slice(-1) === '+' || $('#result').val().slice(-1) === '-' || $('#result').val().slice(-1) === '/' || $('#result').val().slice(-1) === '*') {

    } else {
        var sign = $(this).data('sign');

        $('#result').val(function () {
            resText += sign;
            console.log(sign);
            return this.value;
        });
    }


});

function calc() {
    if (resText.slice(-1) !== '+' &&
        resText.slice(-1) !== '-' &&
        resText.slice(-1) !== '/' &&
        resText.slice(-1) !== '*') {
        console.log(resText);
        console.log(resText.slice(-1));
        var numbers = resText;

        console.log("result: ", eval(resText));
        $('#result').val(eval(resText));
        resText = eval(resText);
    }

}

/*
function one() {
    console.log(typeof $('#result').val());
    if ($('#result').val() === '0') {
        console.log($('#result').val());
        $('#result').val("");
    }
    $("#result").val(function () {
        return this.value + '1';
    });
}

function two() {
    $("#result").append('2');
}

function three() {
    $("#result").append('2');
}*/
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console