css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!-- was created by Spencer Arias. All Rights reserved -->

<!--- VERSION 0.6 8/30/16, fixed a bug where the calculator could not handle more than 12 digits without overflowing. Added the overflow feature and then added the webkit-scrollbar feature to fix this issue. you can no longer have 2 decimals. in the process of fixing a bug that doesn't let you put a decimal immediately after an operator ie. 5.5 * .5 will return Err.  Also looking for a way to make it so the C key removes the last entry but not the whole memory ---->

<!--- VERSION 0.5 8/30/16, Initial Calculator using primarily jQuery ---->


<body>
  <div id="calculator">
    <div class="title"><span id="name">Calculator</span></div> <!-- title -->
    <div id="solution">
      <span id="answer"></span>
    </div> <!-- solution box -->
    
  
    <!-- row 1 -->
    <button class="button1 clear" id="ac">AC</button>
    <button class="button1 clear" id="c">C</button>
    <button class="button1 number" id="divide">÷</button>
    <button class="button1 number" id="multiply">x</button>
    
    <!-- row 2 --> 
    <button class="button1 number" id="seven" value="7">7</button>
    <button class="button1 number" id="eight" value="8">8</button>
    <button class="button1 number" id="nine" value="9">9</button>
    <button class="button1 number" id="subtract">-</button>
    
    <!-- row 3 --> 
    
    <button class="button1 number" id="four" value="4">4</button>
    <button class="button1 number" id="five" value="5">5</button>
    <button class="button1 number" id="six" value="6">6</button>
    <button class="button1 number" id="plus">+</button>
    
    <!-- row 4 -->
    
    <button class="row4 button1 number" id="one" value="1">1</button>
    <button class="row4 button1 number" id="two" value="2">2</button>
    <button class="row4 button1 number" id="three" value="3">3</button>
    <button class="button2 number" id="equals">=</button>
    
    <!-- row 5 -->
    <button class="row5 button3 number" id="zero">0</button>
    <button class="row5 button1 number" id="decimal">.</button>
    
  </div>
  
  <div id="copyright">Designed and Coded by <a href="https://codepen.io/slarias/pen/YWBQdL">Spencer Arias</a></div>
</body>
            
          
!
            
              body {
  background:  #b3b3b3;
  font-family: 'Lato', sans-serif;
  font-size: 1.5em;
}

#calculator {
  background: #bfbfbf;
  position: relative;
  margin: auto;
  top: 100px;
  right: 0;
  bottom: 0;
  left: 0;
  width: 350px;
  height: 490px;
  border: solid;
  border-radius: 15px;
  border-color: #a6a6a6;
  box-shadow: 5px 5px 10px black;
}

.title {
  text-align: center;

}

#name {
  font-size: 1.7em;
  color: black;
  
}

#solution {
  background:  #b8b894;
  border: solid;
  border-radius: 7px;
  border-width: 2px;
  border-color: #a6a6a6;
  height: 70px;
  width: 90%;
  position: relative;
  left: 18px;
  text-align: right;
  padding-right: 10px;
  overflow-x: scroll;
  overflow-y: hidden;    
 
}

  ::-webkit-scrollbar {
    width: 0px;  /* remove scrollbar space */
    background: transparent;  /* optional: just make scrollbar invisible */
}

#answer {
  font-size: 3em;
}



.clear {
  background: #cc0000;
  color:  #e6e6e6;
  border: hidden;
  border-radius: 10px;
  border-width: 2px;
  border-color: #a6a6a6;
  height: 60px;
  width: 70px;
  cursor: pointer;
  outline: none;
  box-shadow: 0 5px #999;
  
}


.clear:active {
  
  box-shadow: 0 5px #666;
  transform: translateY(1px);
}

.number {
  background: #404040;
  color: #e6e6e6;
  border: solid;
  border-radius: 10px;
  border-width: 2px;
  border-color: #a6a6a6;
  height: 60px;
  width: 70px;
  cursor: pointer;
  outline: none;
  box-shadow: 0 5px #999;
  
}

.number:active {
  
  box-shadow: 0 5px #666;
  transform: translateY(1px);
}


.button1 {
  position: relative;
  top: 20px;
  left: 15px;
  margin: 3.5px;
}

.button2 {
  position: relative;
  top: 20px;
  left: 15px;
  margin: 3.5px;
  height: 130px;
}

.button3 {
  position: relative;
  top: 20px;
  left: 15px;
  margin: 3.5px;
  width: 150px;
}

.row4 {
  position: relative;
  top: -15px;
}

.row5 {
  position: relative;
  top: -47px;
}

#copyright {
  position: relative;
  margin: auto;
  text-align: center;
  top: 120px;
  right: 0;
  bottom: 0;
  left: 0;
  font-size: 20px;
}

a {
  color: red;
}
            
          
!
            
              // store all operators
var operators = ['+', '-', '*', '/', '.'];

//create the calculator function
function Check() {
  var lastChar = $('#answer').text().slice(-1);
  for (var i = 0; i < operators.length; i++) {
    if (operators[i] == lastChar) {
      $('#answer').text('Err');
    }
  }
}

// clears the answer
$('#ac').click(function() {
  $('#answer').text('');
});

$('#c').click(function() {
  $('#answer').text('');
});

//operators
$('#plus').click(function() {
  Check();
  $('#answer').text($('#answer').text() + '+');
});

$('#subtract').click(function() {
  Check();
  $('#answer').text($('#answer').text() + '-');
});

$('#multiply').click(function() {
  Check();
  $('#answer').text($('#answer').text() + '*');
});

$('#divide').click(function() {
  Check();
  $('#answer').text($('#answer').text() + '/');
});

$('#decimal').click(function() {
  Check();
  $('#answer').text($('#answer').text() + '.');
  
  if ($('#decimal').text === 2){
    return "NaN";
  } 
  
});

$('#equals').click(function() {
  $('#answer').text(eval($('#answer').text()));
});

//numbers
$('#nine').click(function() {
  $('#answer').text($('#answer').text() + 9);
});

$('#eight').click(function() {
  $('#answer').text($('#answer').text() + 8);
});

$('#seven').click(function() {
  $('#answer').text($('#answer').text() + 7);
});

$('#six').click(function() {
  $('#answer').text($('#answer').text() + 6);
});

$('#five').click(function() {
  $('#answer').text($('#answer').text() + 5);
});

$('#four').click(function() {
  $('#answer').text($('#answer').text() + 4);
});

$('#three').click(function() {
  $('#answer').text($('#answer').text() + 3);
});

$('#two').click(function() {
  $('#answer').text($('#answer').text() + 2);
});

$('#one').click(function() {
  $('#answer').text($('#answer').text() + 1);
});

$('#zero').click(function() {
  $('#answer').text($('#answer').text() + 0);
});




            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console