css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <center>
<div class="calc">

    <button class="clear" onclick="buttonClick('C')">C</button>

    <div id="board" contenteditable ></div>

    <div class="buttons">

        <button onclick="buttonClick('7')">7</button>
        <button onclick="buttonClick('8')">8</button>
        <button onclick="buttonClick('9')">9</button>

        <button class="operator" onclick="buttonClick('+')" >+</button>
        <button onclick="buttonClick('4')">4</button>
        <button onclick="buttonClick('5')">5</button>
        <button onclick="buttonClick('6')">6</button>

        <button class="operator" onclick="buttonClick('-')">-</button>
        <button onclick="buttonClick('1')">1</button>
        <button onclick="buttonClick('2')">2</button>
        <button onclick="buttonClick('3')">3</button>

        <button class="operator" onclick="buttonClick('*')">*</button>
        <button onclick="buttonClick('0')">0</button>
        <button onclick="buttonClick('.')">.</button>
        <button class="eval" onclick="buttonClick('=')">=</button>
        <button class="operator" onclick="buttonClick('/')">÷</button>


    </div>
</div>
</center>


            
          
!
            
              /* STYLES of CALCULATOR APP */

/* font */
@import url('https://fonts.googleapis.com/css?family=Fresca');

/* DIVS' STYLES */

div.calc {
    background-color: white;
    border: solid 2px #83f774;
    border-radius:10px;
/*     box-shadow: 0px 6px 10px #83f774; */
    width: 400px;
    padding: 10px;
    }

div.buttons{
    padding: 5px;
    margin: 5px;
    width: 400px;
}
div#board{
    background-color: #ff5b5b;
    border-radius: 5px;
/*     box-shadow: 0px 0.1px 10px #ff3030; */
    color: white;
    font-family: 'Fresca';
    font-weight: bold;
    font-size: 25px;
    text-align: right;
    width: 380px;
    height: 40px;
    padding: 10px 5px 2px 5px;
}

/* BUTTONS' STYLES */
button{
    background-color: #83f774;
    border: none;
    border-radius: 5px;
    box-shadow: 0px 3px 0.1px 0.01px #15b700;
    color: white;
    cursor: pointer;
    font-size: 30px;
    font-weight: bold;
    font-family: 'Fresca';
    margin-bottom: 5px;
    width:80px;
    height: 60px;
    }

/* eval, operator and clear buttons' styles*/
button.eval{
    background-color: #00def7;
    box-shadow: 0px 3px 1px #008c82;
}

/*-----------------------------------*/
button.operator{
    background-color: #bbff56;
    box-shadow: 0px 3px 1px #64a800;
}

/*--------------------------------------*/
button.clear{
    background-color: #ff5b5b;
    box-shadow: 0px 2px 5px #960000;
    float: left;
    margin-top: 5px;
    margin-left: 10px;
    height:35px;
    padding-right: 10px;
    padding-left: 10px;
    width:35px;
}

/* button hover and click(active) styles */
button:hover{
/*     border-radius: 20px; */
    opacity: 0.7;
}

button:active{
    box-shadow: none;
    transform: translateY(3px);
}

button:focus {outline:0;}/*geting rid of blue line on clicking button*/



            
          
!
            
              function buttonClick(button){
    var display = document.getElementById('board');

    // Checking for numeric buttons
    // if it is number it will add it to the board

    if (isNaN(button) == false) {
        display.innerHTML += button;
    }

    // for clear, operator and eval button
    if(button == 'C'){
        display.innerHTML= '';
    }
    // ----- operator buttons -----
    if (button == '+' || button == '-' || button == '*' || button == '/'){
        // for adding operator button to the expression (not changing)
        if (isNaN(display.innerHTML.slice(-1)) == false && display.innerHTML.length != 0){
            display.innerHTML += button;
        }

        // for adding minus to empty board
        if (button == '-' && display.innerHTML.length == 0){
            display.innerHTML = '-'
                }

        // for changing operator
        if(isNaN(display.innerHTML.slice(-1)) == true){
            display.innerHTML = display.innerHTML.slice(0, -1) + button;
        }

    }
    // ------------------------
    else if (button == '.'){
        if(display.innerHTML.slice(-1) != '.'){
           display.innerHTML+= '.';
       }
    }
    // eval button
    else if (button == '='){
        if (isNaN(display.innerHTML.slice(-1)) == true){
            display.innerHTML= eval(display.innerHTML.slice(0,-1));
        }
        else {display.innerHTML= eval(display.innerHTML);}

    }


}

            
          
!
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