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 class="calculator">

</div>
<div class="calc-container">
  <div class="num-container">
    <div class="num-row">
      <button id="1">1</button>
      <button id="2">2</button>
      <button id="3">3</button>
    </div>
    <div class="num-row">
      <button id="4">4</button>
      <button id="5">5</button>
      <button id="6">6</button>
    </div>
    <div class="num-row">
      <button id="7">7</button>
      <button id="8">8</button>
      <button id="9">9</button>
    </div>
    <div class="num-row">
      <button id="0">0</button>
      <button id="dec">.</button>
    </div>  
  </div> <!-- end num container -->
  <div class="op-container">
    <button id="add">+</button>
    <button id="subtract">-</button>
    <button id="multiply">*</button>
    <button id="divide">/</button>
  </div>
<!--   <button id="enter">Enter</button> -->
</div> <!-- end calc-container -->
  <div class="num-row">
    <button id="clear">Clear</button>
    <button id="enter">=</button>

  </div>

<div id="results"></div>

            
          
!
            
              body {
  background: #2C3E50;
}

.calc-container {
  display: flex;
  flex-direction: row;
  text-align: center;
  justify-content: center;
  margin-top: 3em;
}

.num-container {
  display: flex;
  flex-direction: column;
}

.num-container button {
  background: #225378;
  color: #F3FFE2;
  border: none;
  margin: .1em;
  height: 4em;
  width: 4.5em;
}

.op-container {
  display: flex;
  flex-direction: column;
  margin-left: .6em;
}

.op-container button {
  background: #1695A3;
  color: #F3FFE2;
  border: none;
  margin: .1em;
  height: 4em;
  width: 4.5em;
}

.num-row {
  display: flex;
  flex-direction: row;
  justify-content: center;
}
.op-container {
  display: flex;
  flex-direction: column;
}

#results {
  width: 11em;
  padding: 1em 0 1em 0;
  text-align: center;
  margin-left: auto;
  margin-right: auto;
  margin-top: 10px;
  background: #3498DB;
  color: #fff;
  font-size: 1.5em;
}

button#enter {
  margin-top: 1em;
  background: #85DB18;
  border: none;
  color: #fff;
  height: 3em;
  width: 6em;
  margin-left: 1em;
}

button#clear {
  background: #E74C3C;
  border: none;
  height: 3em;
  width: 6em;
  margin-top: 1em;
  color: #fff;
}
            
          
!
            
              // number variables
var num1 = document.getElementById('1');
var num2 = document.getElementById('2');
var num3 = document.getElementById('3');
var num4 = document.getElementById('4');
var num5 = document.getElementById('5');
var num6 = document.getElementById('6');
var num7 = document.getElementById('7');
var num8 = document.getElementById('8');
var num9 = document.getElementById('9');
var num0 = document.getElementById('0');
var decimal = document.getElementById('dec');

// operator variables
var add = document.getElementById('add');
var subtract = document.getElementById('subtract');
var multiply = document.getElementById('multiply');
var divide = document.getElementById('divide');

var results = document.getElementById('results');
var calculate = document.getElementById('enter');
var clear = document.getElementById('clear');

// onclick functions for each number
num1.onclick = function() {
  results.innerHTML = results.innerHTML + num1.innerHTML;
}
num2.onclick = function() {
  results.innerHTML = results.innerHTML + num2.innerHTML;
}
num3.onclick = function() {
  results.innerHTML = results.innerHTML + num3.innerHTML;
}
num4.onclick = function() {
  results.innerHTML = results.innerHTML + num4.innerHTML;
}
num5.onclick = function() {
  results.innerHTML = results.innerHTML + num5.innerHTML;
}
num6.onclick = function() {
  results.innerHTML = results.innerHTML + num6.innerHTML;
}
num7.onclick = function() {
  results.innerHTML = results.innerHTML + num7.innerHTML;
}
num8.onclick = function() {
  results.innerHTML = results.innerHTML + num8.innerHTML;
}
num9.onclick = function() {
  results.innerHTML = results.innerHTML + num9.innerHTML;
}
num0.onclick = function() {
  results.innerHTML = results.innerHTML + num0.innerHTML;
}
decimal.onclick = function () {
    results.innerHTML = results.innerHTML + decimal.innerHTML;
}
// onclick functions for each operator
add.onclick = function() {
  results.innerHTML = results.innerHTML + add.innerHTML;
}
subtract.onclick = function() {
  results.innerHTML = results.innerHTML + subtract.innerHTML;
}
multiply.onclick = function() {
  results.innerHTML = results.innerHTML + multiply.innerHTML;
}
divide.onclick = function() {
  results.innerHTML = results.innerHTML + divide.innerHTML;
}

calculate.onclick = function() {
  results.innerHTML = eval(results.innerHTML);
}

clear.onclick = function() {
  results.innerHTML = '';
}
            
          
!
999px
Loading ..................

Console