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.

            
              <body>
<div class="container">
    
<div id="calculator-outside">
  <h2 class="title">Da Calculator</h2> 
  <div id="calculator-inside">
    
 <!-- display -->   
 <div id="field">
 <div id="field-equation"></div>
 <div id="field-number">0</div>
 </div>
    
 <!-- keypad -->
 <div id="typepad">
    <button type="button" class="clear" id="AC"     value="AC">AC</button>
    <button type="button" class="clear" id="CE" value="CE">DEL</button>
    <button type="button" class="operation" value="*">x</button>
    <button type="button" class="operation" value="/">&divide;       </button>
    <button type="button" class="number" value="7">7</button>
    <button type="button" class="number" value="8">8</button>
    <button type="button" class="number" value="9">9</button>
    <button type="button" class="operation" value="-">-</button>
    <button type="button" class="number" value="4">4</button>
    <button type="button" class="number" value="5">5</button>
    <button type="button" class="number" value="6">6</button>
    <button type="button" class="operation" value="+">+</button>
    <button type="button" class="number" value="1">1</button>
    <button type="button" class="number" value="2">2</button>
    <button type="button" class="number" value="3">3</button>
    <button type="button" class="equals">=</button>
    <button type="button" class="number" id="zero" value="0">0</button>
    <button type="button" class="number" id="dot" value=".">.</button>
    </div>
    </div>
  </div>
  </div>
</body>
            
          
!
            
              body {
  background-color:#3C4150;
  font-family: 'arial', tahoma;
 }

.title{
  font-family:arial, tahoma;
  text-align:center;
  color: #505256;
  margin-top:8px;
}

#calculator-outside {
  width:320px;
  height:440px; 
  position:absolute;
  top:60%; 
  bottom: 40%;
  left:50%;
  transform:translate(-50%, -50%);
  border-radius:10px;
  box-shadow:10px 10px 20px black;
  background-color:#53e835;
  margin-bottom: 30px;
}

#calculator-inside{
  width:310px;
  height:380px;  
  position:absolute;
  top:50px; 
  left:5px;
  border-radius:10px;
  background-color:#3C4150;
  box-shadow:inset 0px -5px 20px;
}

button {
  font-family: 'Nova Mono', monospace;
  width:54px;
  height:40px;
  background-color:#2b2f3a;
  border:2px;
  border-radius:5px;
  border-style:outset;
  border-color:#c0c0c0;
  margin:5px 10px;
  font-size:1.25em;
  color:white;
  float:left;
}

/* -- display --*/
#field {
  background-color:#818181;
  width:290px;
  height:90px;
  border-radius:10px;
  box-shadow:inset 0px 0px 10px;
  position:absolute;
  left:8px;
  top:10px;
  font-size:2.5em;
  text-align:right;
}

#field-number{
  margin:-10px 5px;
  overflow:hidden;
}

#field-equation{
  height:20px;
  font-size:.4em;
  margin:10px 5px 5px 5px;
  overflow:hidden;
}

/* -- keypad --*/
#typepad {
  width:300px;
  height:280px;
  position:absolute;
  top:105px;
  left:5px;
}

.equals {
  height: 92px;
}

#zero {
  width:130px;
  margin-top:-45px;
}

#dot {
  margin-top:-45px;
  margin-left:158px;
}

#AC {
  background: #74767f;
  color: red;
}

#CE {
  background: #74767f;
  color: red;
}

            
          
!
            
              // If you want an event to work on your page, you should call it inside the $(document).ready() function. Everything inside it will load as soon as the DOM is loaded and before the page contents are loaded.
$(document).ready(function() {
  arrNumber = [];
  arrEquation = [];

  function calculate(arr) {
    str = arr.join(""); //join to become string

    if (str.indexOf("/0") !== -1) { //dividing by 0 = error
      return "Error";
    } else {
      return eval(str); //eval = function evaluates or executes an argument.
    }
  }

  //click = number is pressed to run a function
  $('.number').on("click", function() {
    var number = $(this).val();
    
    if(!(number == "0" && arrNumber[0] == "0" && arrNumber.length == 1) && !(number == "." && arrNumber.indexOf(".")!==-1)){
    arrNumber.push(number);
    $('#field-number').html(arrNumber);
    $('#field-equation').html(arrEquation);
    }
  });
   
    //operation depressed
    $('.operation').on("click", function() {
    var number = arrNumber.join('');
    var operation = $(this).val();

    if (!isNaN(number)) {
      arrEquation.push(number);//push number
      arrNumber = [];
      $('#field-number').html("0");
      arrEquation.push(operation); //push operation
      $('#field-equation').html(arrEquation); //pushed to arrEquation and clear arrNumber
    }
  });
  
    //AC depressed  
    $('.clear').on("click", function() {
    if ($(this).val() == "AC") {
      arrNumber = [];
      arrEquation = [];
      $('#field-number').html("0");
      $('#field-equation').empty(); //empty or clear arrNumbeer & arrEquation
    } else if ($(this).val() == "CE") { //if CE DEL pressed, clear arrNumber
      arrNumber = [];
      $('#field-number').html("0");
    }
  });

   //= pressed
  $('.equals').on("click", function() {
    var number = arrNumber.join('');
    
    if(!isNaN(number)){ //clear both arrays
    arrEquation.push(number);
    $('#field-equation').html(arrEquation);
    $('#field-number').html(parseFloat(calculate(arrEquation).toPrecision(12)));
      //calculate equation and display answer
    arrNumber = [];
    arrEquation = [];
    }
  });
});
            
          
!
999px
Loading ..................

Console