Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

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

Packages

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.

Behavior

Auto Save

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.

HTML

              
                <div class="container-fluid">
  <div class="row vert-spacer"></div>
  <div class="row">
    <div class="col-xs-4"></div>
    <div class="col-sm-4 calculator" id="calculator">
      <div class="row vert-spacer"></div>
      <div class="row display">
        <div class="col-xs-12">
          <ul class="list-group">
            <li class="display-align" id="display">0</li>
          </ul>
        </div>
        <!-- /.col-sm-4 -->
      </div>
      <div class="button-holder">
        <button type="button" class="button-left memory-buttons" id="MC">MC</button>
        <button type="button" class="button memory-buttons" id="MPLUS">M+</button>
        <button type="button" class="button memory-buttons" id="MMINUS">M-</button>
        <button type="button" class="button-right memory-buttons" id="MR">MR</button>
        <button type="button" class="button-left clear-buttons" id="AC">AC</button>
        <button type="button" class="button clear-buttons" id="CE">CE</button>
        <button type="button" class="button compute-buttons" id="percentage">%</button>
        <button type="button" class="button-right compute-buttons" id="divide">&divide;</button>
        <button type="button" class="button-left number-buttons" id="seven">7</button>
        <button type="button" class="button number-buttons" id="eight">8</button>
        <button type="button" class="button number-buttons" id="nine">9</button>
        <button type="button" class="button-right compute-buttons" id="multiply">X</button>
        <button type="button" class="button-left number-buttons" id="four">4</button>
        <button type="button" class="button number-buttons" id="five">5</button>
        <button type="button" class="button number-buttons" id="six">6</button>
        <button type="button" class="button-right compute-buttons" id="subtract">&ndash;</button>
        <button type="button" class="button-left number-buttons" id="one">1</button>
        <button type="button" class="button number-buttons" id="two">2</button>
        <button type="button" class="button number-buttons" id="three">3</button>
        <button type="button" class="button-right compute-buttons" id="add">+</button>
        <button type="button" class="button-left number-buttons" id="zero">0</button>
        <button type="button" class="button number-buttons" id="decimal-point">.</button>
        <button type="button" class="button-equals compute-buttons" id="equal">=</button>
      </div>
      <div class="row vert-spacer"></div>

      <div class="col-xs-4"></div>
    </div>

    <div class="col-xs-4"></div>
  </div>
</div>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Roboto:400,700);

input:focus,I 
select:focus,
textarea:focus,
button:focus {
    outline: none;
}

body {
  background-color: #666;
  font-family: 'Roboto', sans-serif;
  font-size: 16px;
  font-weight: bold;
}

.center {
  text-align: center;
}

.display-align {
  text-align: right;
  font-size: 45px;
  overflow: hidden;
  height: 75px;
  color: #333;
  font-family: 'Roboto', sans-serif;
  font-weight: normal !important;
  padding-top: 20px;
}

.vert-spacer {
  height: 20px;
}

/* new css */

.calculator {
  width: 320px;
  background-color: #333;
  text-align: center;
  box-shadow: 0 0 15px #333;
  margin: 0 auto;
}

.display {
  width: 287px;
  background-color: #fff;
  border: 1px #333 solid;
  margin: 0 auto 0;
}

.button-holder {
  width: 290px;
  margin: 0 auto;
}

.button {
  width: 72px;
  height: 72px;
  border: 0 #333 solid;
  border-left: 1px #333 solid;
  border-bottom: 1px #333 solid;
  margin-left: -4px;
  padding: 0;
  overflow:hidden;
}

.button-right {
  width: 72px;
  height: 72px;
  border: 0 #333 solid;
  border-left: 1px #333 solid;
  border-right: 1px #333 solid;  
  border-bottom: 1px #333 solid;
  padding: 0;
  margin-left: -4px;
}

.button-equals {
  width: 144px;
  height: 72px;
  border: 0 #333 solid;
  border-left: 1px #333 solid;
  border-right: 1px #333 solid;  
  border-bottom: 1px #333 solid;
  padding: 0;
  margin-left: -4px;
}

.button-left {
  width: 72px;
  height: 72px;
  border: 0 #333 solid;  
  border-left: 1px #333 solid;
  border-bottom: 1px #333 solid;
  padding: 0;
  margin-left: 0;
}

.hidden-button {
  background-color: #333;
  width: 68px;
  height: 72px;
  border: 0 #333 solid;
  cursor: default;
}

.memory-buttons {
  background-color: #287d7d;
  color: #fff;
  text-align: center;
}

.memory-buttons:hover {
  background-color: #135e5e;
}

.memory-buttons:active {
  box-shadow: inset 0 0 10px #333;
}

.clear-buttons {
  background-color: #1c344c;
  color: #fff;
  text-align: center;
}

.clear-buttons:hover {
  background-color: #0e243a;
}

.clear-buttons:active {
  box-shadow: inset 0 0 10px #05121f;
}

.number-buttons {
  background-color: #f2f2f2;
  color: #333;
  text-align: center;
}

.number-buttons:hover {
  background-color: #c9c9c9;
  color: #333;
  text-align: center;
}

.number-buttons:active {
  box-shadow: inset 0 0 10px #333;
}

.compute-buttons {
  background-color: #91c46c;
  color: #fff;
  text-align: center;
}

.compute-buttons:hover {
  background-color: #79ab55;
}

.compute-buttons:active {
  box-shadow: inset 0 0 10px #333;
}

              
            
!

JS

              
                $(document).ready(function calculate() {
  var currentNum = 0;
  var tempNum = 0;
  var displayNum = "0";
  var compute = 0; //add = 1, minus = 2, multiply = 3, divide = 4, percentage = 5
  var lastButtonCLicked = 0;
  var percentNum = 0;
  var memoryNum = 0;
  var chainNum = 0;
  var chainCount = 0;
  var decimalCount = 0;

// memory functions buttons
  $('#MC').click(function(evt) {
    var MC = 0;
    //prevent browser's default action
    evt.preventDefault();
    memoryNum = 0;
    document.getElementById("display").innerHTML = "clear";
  }); //end MC button 

  $('#MPLUS').click(function(evt) {
    var MPLUS = 0;
    //prevent browser's default action
    evt.preventDefault();
    memoryNum = memoryNum + currentNum;
    document.getElementById("display").innerHTML = "M+ " + displayNum;
  }); //end MPLUS button    

  $('#MMINUS').click(function(evt) {
    var MMINUS = 0;
    //prevent browser's default action
    evt.preventDefault();
    memoryNum = memoryNum - currentNum;
    document.getElementById("display").innerHTML = "M- " + displayNum;
  }); //end MMINUS button   

  $('#MR').click(function(evt) {
    var MR = 0;
    //prevent browser's default action
    evt.preventDefault();
    currentNum = memoryNum;
    displayNum = memoryNum.toString();
    document.getElementById("display").innerHTML = displayNum;
  }); //end MMINUS button  
  
// end memory functions buttons
  
  
// clear functions buttons
  $('#AC').click(function(evt) {
    var AC = 0;
    //prevent browser's default action
    evt.preventDefault();
    currentNum = 0;
    displayNum = "0";
    chainNum = 0;
    chainCount = 0;
    decimalCount = 0;
    document.getElementById("display").style.fontSize = "45px";
    document.getElementById("display").innerHTML = 0;
  }); //end AC button

  $('#CE').click(function(evt) {
    var CE = 0;
    //prevent browser's default action
    evt.preventDefault();
    displayNum = displayNum.slice(0, -1);
    if (displayNum.length === 0) {
      currentNum = 0;
      displayNum = "0";
      document.getElementById("display").innerHTML = displayNum;
    } else {
      currentNum = Number(displayNum);
      document.getElementById("display").innerHTML = displayNum;
    }
    if (decimalCount === 1) {
      decimalCount = 0;
    }
  }); //end AC button  
  
// end clear functions buttons
  
  
  
// function to run when a number is clicked
  function numClick(literalNum, stringNum) {
    lastButtonCLicked = literalNum;
    
    if (displayNum === "0") {
      displayNum = displayNum.replace("0", stringNum);
      currentNum = literalNum;
      document.getElementById("display").innerHTML = displayNum;
    } else {
      displayNum = displayNum.concat(stringNum);
      currentNum = Number(displayNum);
      document.getElementById("display").innerHTML = displayNum;
    }
  }; //end numClick  
  

// 0-9 number click functions
  $('#zero').click(function(evt) {
    numClick(0, "0");    
  }); //end zero button   

  $('#one').click(function(evt) {
    numClick(1, "1");    
  }); //end one button    
  
  $('#two').click(function(evt) {
    numClick(2, "2");    
  }); //end two button    
      
  $('#three').click(function(evt) {
    numClick(3, "3");    
  }); //end three button 

  $('#four').click(function(evt) {
    numClick(4, "4");    
  }); //end four button 

  $('#five').click(function(evt) {
    numClick(5, "5");    
  }); //end five button 

  $('#six').click(function(evt) {
    numClick(6, "6");    
  }); //end six button 

  $('#seven').click(function(evt) {
    numClick(7, "7");    
  }); //end seven button 

  $('#eight').click(function(evt) {
    numClick(8, "8");    
  }); //end eight button 

  $('#nine').click(function(evt) {
    numClick(9, "9");    
  }); //end nine button 
  
// end number click functions
  
  
  
// decimal and computation buttons
  $('#decimal-point').click(function(evt) {
    lastButtonCLicked = 0.0;
    //prevent browser's default action
    evt.preventDefault();
    if (displayNum === "0" && decimalCount === 0) {
      displayNum = displayNum.replace("0", "0.");
      currentNum = 0.0;
      decimalCount = 1;
      document.getElementById("display").innerHTML = displayNum;
    } else if (decimalCount === 0) {
      displayNum = displayNum.concat(".");
      currentNum = Number(displayNum);
      decimalCount = 1;
      document.getElementById("display").innerHTML = displayNum;
    } else {
      displayNum = displayNum.concat("");
      currentNum = Number(displayNum);
      document.getElementById("display").innerHTML = displayNum;
    }
  }); //end decimal button  

  $('#add').click(function(evt) {
    compute = 1;
    tempNum = currentNum;
    chainNum = chainNum + currentNum;
    displayNum = "";
    currentNum = 0;
    chainCount++;
    decimalCount = 0;
    document.getElementById("display").innerHTML = chainNum.toString();
    //prevent browser's default action
    evt.preventDefault();
  }); //end add button

  $('#subtract').click(function(evt) {
    compute = 2;
    tempNum = currentNum;
    decimalCount = 0;
    if (chainNum === 0) {
      chainNum = Math.abs(chainNum - currentNum);
    } else {
      chainNum = chainNum - currentNum;
    }
    currentNum = 0;
    displayNum = "";
    chainCount++;
    document.getElementById("display").innerHTML = chainNum.toString();
    //prevent browser's default action
    evt.preventDefault();
  }); //end add button

  $('#multiply').click(function(evt) {
    compute = 3;
    tempNum = currentNum;
    decimalCount = 0;
    if (chainNum === 0) {
      chainNum = 1;
      chainNum = chainNum * currentNum;
    } else {
      chainNum = chainNum * currentNum;
    }
    currentNum = 0;
    displayNum = "";
    chainCount++;
    document.getElementById("display").innerHTML = chainNum.toString();
    //prevent browser's default action
    evt.preventDefault();
  }); //end multiply button

  $('#divide').click(function(evt) {
    compute = 4;
    tempNum = currentNum;
    decimalCount = 0;
    if (chainNum === 0) {
      chainNum = 1;
      chainNum = currentNum / chainNum;
    } else {
      chainNum = chainNum / currentNum;
    }
    currentNum = 0;
    displayNum = "";
    chainCount++;
    document.getElementById("display").innerHTML = chainNum.toString();
    //prevent browser's default action
    evt.preventDefault();
  }); //end divide button  

  $('#percentage').click(function(evt) { // Note: there seems to be some disparity on how the percentage button should work. On the iOS stock calculator, the percentage button simply outputs the result of the the percentage of the first number. However, most calculators take that result and add it to the original amount, turning the percentage button into a tax calculator of sorts. I have decided to use this second method as well.
    compute = 5;
    percentNum = currentNum;
    decimalCount = 0;
    console.log(chainCount);
    if (chainCount < 1) {
      document.getElementById("display").innerHTML = "0";
      currentNum = 0;
      displayNum = "";
    } else if (chainCount >= 1) {
      if (chainNum === 0) {
        chainNum = 1;
        chainNum = chainNum * (percentNum / 100);
        chainNum = chainNum + tempNum;
      } else {
        chainNum = chainNum * (percentNum / 100);
        chainNum = chainNum + tempNum;
      }
      currentNum = 0;
      displayNum = "";
      document.getElementById("display").innerHTML = chainNum.toString();
    }

    //prevent browser's default action
    evt.preventDefault();
  }); //end percentage button  

  $('#equal').click(function(evt) {
    decimalCount = 0;
    if (chainCount < 1) {
      if (compute == 1) {
        currentNum = tempNum + currentNum;
        displayNum = currentNum.toString();
      } else if (compute == 2) {
        currentNum = tempNum - currentNum;
        displayNum = currentNum.toString();
      } else if (compute == 3) {
        currentNum = tempNum * currentNum;
        displayNum = currentNum.toString();
      } else if (compute == 4) {
        currentNum = tempNum / currentNum;
        displayNum = currentNum.toString();
      }
      if (displayNum.length > 10) {
        document.getElementById("display").style.fontSize = "25px";
        document.getElementById("display").innerHTML = displayNum;
      } else {
        document.getElementById("display").innerHTML = displayNum;
      }
    } else if (chainCount >= 1) {
      if (compute == 1) {
        chainNum = chainNum + currentNum;
        displayNum = "";
        currentNum = 0;
        document.getElementById("display").innerHTML = chainNum.toString();
        chainCount = chainCount++;
      } else if (compute == 2) {
        tempNum = currentNum;
        if (chainNum === 0) {
          chainNum = Math.abs(chainNum - currentNum);
        } else {
          chainNum = chainNum - currentNum;
        }
        currentNum = 0;
        displayNum = "";
        document.getElementById("display").innerHTML = chainNum.toString();
      } else if (compute == 3) {
        tempNum = currentNum;
        if (chainNum === 0) {
          chainNum = 1;
          chainNum = chainNum * currentNum;
        } else {
          chainNum = chainNum * currentNum;
        }
        currentNum = 0;
        displayNum = "";
        document.getElementById("display").innerHTML = chainNum.toString();
      } else if (compute == 4) {
        tempNum = currentNum;
        if (chainNum === 0) {
          chainNum = 1;
          chainNum = currentNum / chainNum;
        } else {
          chainNum = chainNum / currentNum;
        }
        currentNum = 0;
        displayNum = "";
        document.getElementById("display").innerHTML = chainNum.toString();
      }
    }

    //prevent browser's default action
    evt.preventDefault();
  }); //end equal button

}); //end document ready
              
            
!
999px

Console