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.

Quick-add: + add another resource

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.

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.

            
              <div id='calculatorJS' class='clearfix effect'>

  <div id='topBox'>
    <div id="calcText"><span>JavaScript Calculator</span></div>
    <div id='screen'></div>
  </div>
  <!-- end topBox -->

  <div id='btnsWrapper' class='clearfix'>

    <div id='btnTopRow' class='clearfix'>
      <button type='button' id='c' class='btn' name='c'>C</button>
    </div>
    <!-- end btnTopRow -->

    <div id='numBtns'>
      <button type='button' id='seven' class='btn' name='seven' value='7'>7</button>
      <button type='button' id='eight' class='btn' name='eight' value='8'>8</button>
      <button type='button' id='nine' class='btn' name='nine' value='9'>9</button>
      <button type='button' id='four' class='btn' name='four' value='4'>4</button>
      <button type='button' id='five' class='btn' name='five' value='5'>5</button>
      <button type='button' id='six' class='btn' name='six' value='6'>6</button>
      <button type='button' id='one' class='btn' name='one' value='1'>1</button>
      <button type='button' id='two' class='btn' name='two' value='2'>2</button>
      <button type='button' id='three' class='btn' name='three' value='3'>3</button><button type='button' id='zero' class='btn' name='zero' value='0'>0</button><button type='button' id='decimal' class='btn' name='decimal' value='.'>.</button><button type='button' id='equals' class='btn' name='equals'>=</button></div><!-- end numBtns --><div id='arithmeticBtns' class='clearfix'>
      <button type='button' id='divide' class='btn' name='divide' value='divide'>/</button><button type='button' id='multiply' class='btn' name='multiply' value='multiply'>*</button>
      <button type='button' id='minus' class='btn' name='minus' value='subtract'>-</button>
    <button type='button' id='plus' class='btn' name='plus' value='add'>+</button>
   </div> <!-- arithmeticBtns -->


  </div>
  <!-- end btnWrapper -->
</div>
<!-- end calculatorJS -->
            
          
!
            
              * {
  box-sizing: border-box;
}
.wrapper {
}

#calcText {
color: white;
 width: 100%;
  text-align: center;
}
.clearfix:after {
    content:" ";
    display:block;
    clear:both;
}
#calculatorJS {
  width: 100%;
  min-width: 175px;
  max-width: 275px;
  margin: 1em auto;
  background-color: #161C28;
  border-radius: 10px;
box-shadow: inset 0px 0px 5px rgba(0,0,0,.5), inset 1px 1px 15px rgba(255,255,255,.3);

}
#topBox {
  width: 100%;
  margin: 0 auto;
  padding: 1em .5em;
  background-color: #252B37;
  border-bottom: 1px solid black;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
  box-shadow: inset 0px 0px 5px rgba(0,0,0,.5), inset 1px 1px 0px rgba(255,255,255,.3);
}
#screen {
  overflow: hidden;
  width: 100%;
  padding: .5em 5px .5em 0;
  margin-top: .5em;
  background-color: DarkSeaGreen;
  border: 1px solid silver;
  border-radius: 5px;
  font-size: 1.3em;
  text-align: right;
  box-shadow: inset 0px 0px 6px black;
}
#btnsWrapper {
  width: 100%;
  padding: 0 .5em 1em;
}
button:focus {outline:0;}
.btn {
  color:white;
  float: left;
  border-radius: 7px;
  background-color: black;
  border-top: 2px solid dimgrey;
   border-left: 2px solid dimgrey;
  border-right: 2px solid dimgrey;
  border-bottom: 3px solid grey;
}
.btn:active {
  border-top: 2px solid grey;
  border-left: 2px solid grey;
  border-right: 2px solid grey;
  border-bottom: 2px solid grey;
}
#btnTopRow {
  width: 100%;
  clear: both;
  margin-bottom: 5%;
}
#numBtns {
  float: left;
  width: 75%;
}
#numBtns button {
  width: 30%;
  height: 2em;
  margin: 0 0 .8em 4%;
}
#numBtns button:nth-child(3n+1) {
  margin-left:0;
}
#arithmeticBtns {
  width: 25%;
  float: left;
}
#arithmeticBtns button {
  width: 100%;
  height: 2em;
  margin: 0 0 .8em 4%;
}
#c {
  width: 21%;
  height: 2em;
  margin-top: .8em;
  color: red;
  
}
#equals {

}
.effect
{
    position:relative;
    box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset;
}
.effect:before, .effect:after
{
	content:"";
    position:absolute; 
    z-index:-1;
    box-shadow:0 0 20px rgba(0,0,0,0.8);
    top:10px;
    bottom:10px;
    left:0;
    right:0;
    border-radius:100px / 10px;
} 
.effect:after
{
    right:10px; 
    left:auto; 
    transform:skew(8deg) rotate(3deg);
}
            
          
!
            
              var nums = [
  [],
  []
];
var operator;
var operand = 0;
var total = 0;
var arithCount = 0;
var afterEquals = false;
var c = document.querySelector('#c');
var arithmetic = document.querySelector('#arithmeticBtns');
var numBtnArea = document.querySelector('#numBtns');
var screen = document.querySelector('#screen');
var math = {
  add: function(a, b) {
    return a + b;
  },
  subtract: function(a, b) {
    return a - b;
  },
  multiply: function(a, b) {
    return a * b;
  },
  divide: function(a, b) {
    return a / b;
  }
};

numBtnArea.addEventListener('click', numPress, false);
c.addEventListener('click', clear, false);
arithmetic.addEventListener('click', arithmeticOperator, false);

clear();

function testIfDecimal(str) {
  return /\.*/.test(str) ? parseFloat(str) : parseInt(str);
}

// calculate total and print
function numsTotal() {
  total = math[operator](testIfDecimal(nums[0].join('')), testIfDecimal(nums[1].join('')));
  nums[0] = [total];
  afterEquals = true;
  operand = 1;
  screen.innerHTML = total;
}
// event when arithmetic btn is pressed
function arithmeticOperator(e) {
  if (e.target !== e.currentTarget) {
    if (nums[0].length < 1) {
      console.log('empty');
      return;
    }
    if (arithCount < 2) {
      arithCount++;
    }
    if (afterEquals === true) {
      nums[1] = [];
    }
    // } else if (arithCount === 2) {
    //   console.log('this one');
    //  // numsTotal();
    //   arithCount = 1;
    //   nums[1] = [];
    // } else if (arithCount > 2) {
    //   alert('over');
    //   return;
    // }
    afterEquals = false;
    operand = 1;
    operator = e.target.value;
  }
}
// event when number, equals, or decimal btn is pressed
function numPress(e) {
  if (e.target.id === "equals") {
    // if no operands then don't continue
    if (operand === 0) {
      return;
    }
    numsTotal();
    return;
  }
  if (e.target !== e.currentTarget) {
    if (arithCount === 3) {
      arithCount = 1;
    }
    if (afterEquals === true) {
      clear();
    }

    if (e.target.id === 'decimal') {
      if (nums[operand].length === 0) {
        nums[operand].push('0');
      }
      if (nums[operand].indexOf('.') !== -1) {
        return;
      }
    }
    nums[operand].push(e.target.value);
    screen.innerHTML = nums[operand].join('');
  }
} // end numPress

function clear() {
  nums = [
    [],
    []
  ];
  screen.innerHTML = 0;
  operand = 0;
  afterEquals = false;
  arithCount = 0;
}
            
          
!
999px
Loading ..................

Console