Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body>

    <div class="container">

        <!-- <div class="display"> 

        <div class="top-display">
            <h3 id='main-display'></h3>
        </div> -->

        <div class="bot-display">
            <h2 id='input-display'></h2>
        </div>

        <!-- </div> -->

        <div class="key-pad">

            <button id="clear"> &#67; </button>
            <button id="sign"> &#45;&#47;&#43; </button>
            <button id="percent"> &#37; </button>
            <button id="divide" class="last-char"> &#247; </button>

        </div>

        <div class="key-pad">

            <button id="seven"> &#55; </button>
            <button id="eight"> &#56; </button>
            <button id="nine"> &#57; </button>
            <button id="mult" class="last-char"> &#42; </button>

        </div>

        <div class="key-pad">

            <button id="four"> &#52; </button>
            <button id="five"> &#53; </button>
            <button id="six"> &#54; </button>
            <button id="sub" class="last-char"> &#45; </button>

        </div>

        <div class="key-pad">

            <button id="one"> &#49; </button>
            <button id="two"> &#50; </button>
            <button id="three"> &#51; </button>
            <button id="add" class="last-char"> &#43; </button>

        </div>

        <div class="key-pad-last">

            <button id="zero"> &#48; </button>
            <button id="period"> &#46; </button>
            <button id="delete"> DEL </button>
            <button id="equal" class="last"> &#61; </button>

        </div>

    </div>


</body>

              
            
!

CSS

              
                body {
    background-color: #1D2225;
    margin: 0px;
    padding: 0px;
    color: white;
}


/* .container */

.container {
    height: 555px;
    width: 414px;
    /* border: 1px solid gray; */
    margin: 10% auto;
    border-radius: 2px;
    -webkit-box-shadow: 0px 0px 144px 30px rgba(0, 0, 0, 0.49);
    -moz-box-shadow: 0px 0px 144px 30px rgba(0, 0, 0, 0.49);
    box-shadow: 0px 0px 144px 30px rgba(0, 0, 0, 0.49);
}


/* .display */

.display {
    height: 250px;
    background-color: #FAFAFA;
    margin-bottom: 0;
    border-top-left-radius: 2px;
    border-top-right-radius: 2px;
}

.top-display {
    text-align: right;
    background-color: #FAFAFA;
    color: black;
    font-size: 2rem;
    /* margin: 0px 0px; */
    height: 150px;
    /* padding: 20px 30px; */
    border-bottom: 1px solid black;
    /* border: 2px solid black; */
}

/*#main-display {
    padding: 50px 20px;
    border: 1px solid black;
    height: 0px; 
}*/

.bot-display {
    text-align: right;
    background-color: #FAFAFA;
    color: black;
    font-size: 24px;
    /* margin: 0px 0px; */
    height: 100px;
    padding: 25px 20px;
    /* border: 1px solid white; */
}


/* keys */

.key-pad {
    border-bottom: 1px solid #A1A2A2;
    font-size: 0px
    /* padding: 0px 10px; */
}

.key-pad-last {
    border-bottom: none;
    font-size: 0;
    /* padding: 0px 10px; */
}


/* buttons */

button {
    border-top: none;
    border-bottom: none;
    border-left: none;
    border-right: 1px solid #A1A2A2;
    background-color: #1D2225;
    color: #D0D2D4;
    font-size: 30px;
    text-decoration: none;
    height: 80px;
    width: 25%;
    font-family: 'Quicksand', sans-serif;
    font-weight: 300;
    /* margin-left: 8px; */
}

.last-char, .last {
    background-color: #5E4BB5;
    border-right: none;
}

/*
.last {
     background-color: #FEC208;
    background-color: #5E4BB5;
}
 */


/*
.last-char {
    border-right: 1px solid #A1A2A2;
}

ul {
    display: inline-block;
}

li {
    display: inline;
    height: 100px;
}



ul li {
    margin: auto;
    font-size: 2rem;
    padding: 5%;
} */
              
            
!

JS

              
                //////////////////////////////////////////////////////////// GLOBAL ////////////////////////////////////////////////////////////////////////////
var s = ''; //initializing string to be evaluated


// var digitsArray = [];
// var result = 0;

//variable operatos to be disabled or enable
var percent = document.getElementById('percent'); 
var divide  = document.getElementById('divide'); 
var mult    = document.getElementById('mult');
var sub     = document.getElementById('sub');
var add     = document.getElementById('add');
var period  = document.getElementById('period');
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////Digits or numbers ///////////////////////////////////////////////////////////////////////////////

document.getElementById('one').addEventListener('click', function() {
    // document.getElementById('input-display').innerText = one;
    // digitsArray.push(1);
    
    // enables operators if a number is pressed.
    percent.disabled = false;
    divide.disabled  = false;
    mult.disabled    = false;
    sub.disabled     = false;
    add.disabled     = false;
    period.disabled  = false;
    s += 1;
    holder();
});

document.getElementById('two').addEventListener('click', function() {
    // document.getElementById('input-display').innerText = two;
    // digitsArray.push(2);

    // enables operators if a number is pressed.
    percent.disabled = false;
    divide.disabled  = false;
    mult.disabled    = false;
    sub.disabled     = false;
    add.disabled     = false;
    period.disabled  = false;
    s += 2;
    holder();
});

document.getElementById('three').addEventListener('click', function() {
    // document.getElementById('input-display').innerText = three;
    // digitsArray.push(3);

    // enables operators if a number is pressed.
    percent.disabled = false;
    divide.disabled  = false;
    mult.disabled    = false;
    sub.disabled     = false;
    add.disabled     = false;
    period.disabled  = false;
    s += 3;
    holder();
});

document.getElementById('four').addEventListener('click', function() {
    // document.getElementById('input-display').innerText = four;
    // digitsArray.push(4);

    // enables operators if a number is pressed.
    percent.disabled = false;
    divide.disabled  = false;
    mult.disabled    = false;
    sub.disabled     = false;
    add.disabled     = false;
    period.disabled  = false;
    s += 4;
    holder();
});

document.getElementById('five').addEventListener('click', function() {
    // document.getElementById('input-display').innerText = five;
    // digitsArray.push(5);

    // enables operators if a number is pressed.
    percent.disabled = false;
    divide.disabled  = false;
    mult.disabled    = false;
    sub.disabled     = false;
    add.disabled     = false;
    period.disabled  = false;
    s += 5;
    holder();
});

document.getElementById('six').addEventListener('click', function() {
    // document.getElementById('input-display').innerText = six;
    // digitsArray.push(6);

    // enables operators if a number is pressed.
    percent.disabled = false;
    divide.disabled  = false;
    mult.disabled    = false;
    sub.disabled     = false;
    add.disabled     = false;
    period.disabled  = false;
    s += 6;
    holder();
});

document.getElementById('seven').addEventListener('click', function() {
    // document.getElementById('input-display').innerText = seven;
    // digitsArray.push(7);

    // enables operators if a number is pressed.
    percent.disabled = false;
    divide.disabled  = false;
    mult.disabled    = false;
    sub.disabled     = false;
    add.disabled     = false;
    period.disabled  = false;
    s += 7;
    holder();
});

document.getElementById('eight').addEventListener('click', function() {
    // document.getElementById('input-display').innerText = eight;
    // digitsArray.push(8);

    // enables operators if a number is pressed.
    percent.disabled = false;
    divide.disabled  = false;
    mult.disabled    = false;
    sub.disabled     = false;
    add.disabled     = false;
    period.disabled  = false;
    s += 8;
    holder();
});

document.getElementById('nine').addEventListener('click', function() {
    // document.getElementById('input-display').innerText = nine;
    // digitsArray.push(9);

    // enables operators if a number is pressed.
    percent.disabled = false;
    divide.disabled  = false;
    mult.disabled    = false;
    sub.disabled     = false;
    add.disabled     = false;
    period.disabled  = false;
    s += 9;
    holder();
});

document.getElementById('zero').addEventListener('click', function() {
    // document.getElementById('input-display').innerText = zero;
    // digitsArray.push(0);

    //enables operators if a number is pressed.
    percent.disabled = false;
    divide.disabled  = false;
    mult.disabled    = false;
    sub.disabled     = false;
    add.disabled     = false;
    period.disabled  = false;
    s += 0;
    holder();
});
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////// Operators ///////////////////////////////////////////////////////////////////////////////
document.getElementById('percent').addEventListener('click', function() {
    
    //disables the operators if the operatos are pressed.
    percent.disabled = true; 
    divide.disabled  = true;
    mult.disabled    = true;   
    sub.disabled     = true;    
    add.disabled     = true;    
    period.disabled  = true; 
    s += '%';
    holder();
});

document.getElementById('divide').addEventListener('click', function() {
    //   var diver = document.getElementById('main-display').innerHTML = digitsArray.join('');
    //   diver = parseInt(diver, 10);
    //   digitsArray = [];
    //   document.getElementById('input-display').innerHTML = "";
    //   totalResult(result);

    //disables the operators if the operatos are pressed.
    percent.disabled = true; 
    divide.disabled  = true;
    mult.disabled    = true;   
    sub.disabled     = true;    
    add.disabled     = true;    
    period.disabled  = true;
    s += '/';
    holder();
});

document.getElementById('mult').addEventListener('click', function() {
    //   var multer = document.getElementById('main-display').innerHTML = digitsArray.join('');
    //   multer = parseInt(multer, 10);
    //   digitsArray = [];
    //   document.getElementById('input-display').innerHTML = "";
    //   totalResult(result);

    //disables the operators if the operatos are pressed.
    percent.disabled = true; 
    divide.disabled  = true;
    mult.disabled    = true;   
    sub.disabled     = true;    
    add.disabled     = true;    
    period.disabled  = true;
    s += '*';
    holder();
});

document.getElementById('sub').addEventListener('click', function() {
    // var suber = document.getElementById('main-display').innerHTML = digitsArray.join('');
    // suber = parseInt(suber, 10);
    // digitsArray = [];
    // document.getElementById('input-display').innerHTML = "";
    // totalResult(result);

    //disables the operators if the operatos are pressed.
    percent.disabled = true; 
    divide.disabled  = true;
    mult.disabled    = true;   
    sub.disabled     = true;    
    add.disabled     = true;    
    period.disabled  = true;
    s += '-';
    holder(); 
});

document.getElementById('add').addEventListener('click', function() {
    // var adder = document.getElementById('main-display').innerHTML = digitsArray.join('');
    // adder = parseInt(adder, 10);
    // digitsArray = [];
    // document.getElementById('input-display').innerHTML = "";
    // totalResult(result);

    //disables the operators if the operatos are pressed.
    percent.disabled = true; 
    divide.disabled  = true;
    mult.disabled    = true;   
    sub.disabled     = true;    
    add.disabled     = true;    
    period.disabled  = true;
    s += '+';
    holder();
});

document.getElementById('period').addEventListener('click', function() {
    
    //disables the operators if the operatos are pressed.
    percent.disabled = true; 
    divide.disabled  = true;
    mult.disabled    = true;   
    sub.disabled     = true;    
    add.disabled     = true;    
    period.disabled  = true;
    s += '.';
    holder();
});
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////// keys ///////////////////////////////////////////////////////////////////////////////

document.getElementById('delete').addEventListener('click', function() {
    // digitsArray.pop();
    // holder();

    //deletes the last entered character
    s = s.substr(0, s.length -1);
    document.getElementById('input-display').innerHTML = s;
});

document.getElementById('equal').addEventListener('click', function() {
    
    // document.getElementById('main-display').innerHTML = eval(s);

    //displays the evaluated string.
    document.getElementById('input-display').innerHTML = eval(s);

    //enables the button if pressed
    percent.disabled = false; 
    divide.disabled  = false;
    mult.disabled    = false;   
    sub.disabled     = false;    
    add.disabled     = false;    
    period.disabled  = false;

    //clears the string variable
    s = '';
   
    //  document.getElementById('input-display').innerHTML = '';
    
});

document.getElementById('sign').addEventListener('click', function() {

});

document.getElementById('clear').addEventListener('click', function() {
    
    //clears the displays
    document.getElementById('input-display').innerHTML = "";
    //document.getElementById('main-display').innerHTML = "";
    s = '';
    // digitsArray = [];
    
});
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////// FUNCTIONS ///////////////////////////////////////////////////////////////////////////////

// function totalResult(val) {
//     document.getElementById('main-display').innerHTML = val;
//     // console.log(val, 'looooggg');
// }

//function to display the string.
function holder() {
    // var res = document.getElementById('input-display').innerHTML = digitsArray.join('');
    var res = document.getElementById('input-display').innerHTML = s;
}

// checkStr('1+2/');

// function checkStr(string) {

// var add = string[string.length -1] === '+';
// var div = string[string.length -1] === '/';
// var sub = string[string.length -1] === '-';
// var mult = string[string.length -1] === '*';

// console.log( add || div || sub || mult );


//if the condition is true then disable. 

//check nov 3.

//}
              
            
!
999px

Console