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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <center>
<div class="calc">

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

    <div id="board"></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: 20px;
    box-shadow: 0px 6px 10px #83f774;
    width: 500px;
    padding: 10px;
    }

div.buttons{
    padding: 5px;
    margin: 5px;
    width: 400px;
}
div#board{
    background-color: #ff5b5b;
    border-radius: 10px;
    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: 10px;
    box-shadow: 0px 3px 1px #15b700;
    color: white;
    cursor: pointer;
    font-size: 30px;
    font-weight: bold;
    font-family: 'Fresca';
    margin-bottom: 5px;
    width:95px;
    height: 95px;
    transition: border-radius 0.5s,
                opacity 0.5s, transform 0.2s,
                box-shadow 0.2s;
}

/* 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*/

button.clear:hover{
    border-radius: 15px;
}

            
          
!
            
              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
Loading ..................

Console