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


Babel includes JSX processing.

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


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


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.


  <div class="container-fluid text-center">
    <div class="row">
      <h1> Calculator </h1>
      <h3> Math is Fun </h3>
    <div class="row"> 
      <!-- Start calculator -->
      <div id="calculator">
        <div class="top">
          <span class="clear">C</span>
          <div class="screen"></div>
        <div class="keys">
        <!-- operators and other keys -->
          <span class="operator">+</span>
          <span class="operator">-</span>
          <span class="operator">÷</span>
          <span class="eval">=</span>
          <span class="operator">x</span>
      <!-- End calculator -->
    <div class="row text-center"> <!-- for footer -->
      <h4>Video tutorial <a href="" target="_blank">here</a></h4>
      <h5><a href="" target="_blank">Eleftheria </a> | <a href="" target="_blank">Projects</a> | <a href="" target="_blank"> Coding videos </a></h5>
    </div> <!-- end footer -->
  </div> <!-- end class container-fluid --> 


                body {
  background-color: #B2127D; /* purple */
  color: #14C6CC;            /* blue */

/* yellow: #FFDF27
dark blue: #1BADB2 
almost white: #FFF0F5*/

  width: 325px;
  height: auto;
  margin: 5% auto;
  padding: 20px 20px 10px;
  background: #14C6CC;
  background: linear-gradient(#14C6CC, #FFDF27);
  border-radius: 50px;

.top span.clear {
  float: left;

.top .screen {
  height: 40px;
  width: 212px;
  float: right;
  padding: 0 10px;
  background: #1BADB2;
  border-radius: 50px;
  font-size: 20px;
  line-height: 40px;
  color: white;
  text-align: right;
  letter-spacing: 1px;

.keys, .top {overflow:hidden}

.keys span, .top span.clear{
  position: relative;
  top: 0px;
  width: 66px;
  height: 36px;
  background: white;
  border-radius: 20px;
  margin: 0 7px 11px 0;
  color:  #B2127D;
  line-height: 36px;
  text-align: center;
  user-select: none;
  transition: all 0.2s ease;

.keys span.operator {
  background: #FFF0F5;
  margin-right: 0;

.keys span.eval {
  background: #14C6CC;
  color: #B2127D;

.top span.clear {
  background: #FFDF27;
  color: #B2127D;

.keys span:hover {
  background: #14C6CC;
  color: white;

.keys span.eval:hover {
  background: #B2127D;
  color: white;

.keys span.clear:hover {
  background: #B2127D;
  color: white;


                // Get all the keys from document
var keys = document.querySelectorAll('#calculator span');
var operators = ['+', '-', 'x', '÷'];
var demimalAdded = false;

for (var i=0; i<keys.length; i++){
  keys[i].onclick = function(e){
    var input = document.querySelector('.screen');
    var inputVal = input.innerHTML;
    var btnVal = this.innerHTML;
    if (btnVal == 'C') {
      input.innerHTML = '';
      demimalAdded = false;
    } else if (btnVal == '=') {
      var equation = inputVal;
      var lastChar = equation[equation.length - 1];
      equation = equation.replace(/x/g, '*').replace(/÷/g, '/');
      if (operators.indexOf(lastChar) > 1 || lastChar == '.')
        equation = equation.replace(/.$/, '');
      if (equation)
        input.innerHTML = eval(equation);
      demimalAdded = false;
    else if(operators.indexOf(btnVal) > -1) {
      var lastChar = inputVal[inputVal.length -1];
      if (inputVal != '' && operators.indexOf(lastChar) == -1)
        input.innerHTML +=btnVal;
      else if(inputVal == '' && btnVal == '-')
        input.innerHTML +=btnVal;
      if(operators.indexOf(lastChar) > 1 && inputVal.length > 1) {
        input.innerHTML = inputVal.replace(/.$/, btnVal);
      demimalAdded = false;
    } else if(btnVal == '.') {
      if(!demimalAdded) {
        input.innerHTML +=btnVal;
        demimalAdded = true;
    else {
      input.innerHTML += btnVal;