Pen Settings

HTML

CSS

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

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

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.

HTML

              
                <!DOCTYPE html>
<html lang="en">

<head>
  <!-- Required meta tags always come first -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">

  <title> Bootstrap + Fontawesome + jQuery + tether </title>

  <!-- Bootstrap CSS -->
  <!-- Latest compiled and minified CSS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

  <!-- Optional Bootstrap theme -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

  <!-- font awesome -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.0/css/font-awesome.min.css" />
  <style>
    .display-main {
      /*font-family: monospace;*/
      text-align: right;
      font-size: 36pt;
    }

    .display-breadcrumbs {
      text-align: right;
      margin-right: 20px;
      margin-bottom: 20px;
    }

    button {
      width: 100%;
      height: 100%;
    }

    .btndiv {
      padding: 0px;
    }
  </style>
</head>

<body>
  <div class="container">


    <div class="row header-row">
    </div>

    <div class="row app-row">
      <div class="col-xs-12 calculator">
        <div class="row display-main">
          0
        </div>
        <div class="row display-breadcrumbs">
          0
        </div>
        <div class="row keypad-row">
          <div class="btndiv btndiv col-xs-3" id="ac-clear-div">AC</div>
          <div class="btndiv col-xs-3" id="c-clear-div">C</div>
          <div class="btndiv col-xs-3" id="divide-op-div">/</div>
          <div class="btndiv col-xs-3" id="multiply-op-div">X</div>
        </div>
        <div class="row keypad-row">
          <div class="btndiv col-xs-3" id="7-num-div">7</div>
          <div class="btndiv col-xs-3" id="8-num-div">8</div>
          <div class="btndiv col-xs-3" id="9-num-div">9</div>
          <div class="btndiv col-xs-3" id="add-op-div">+</div>
        </div>
        <div class="row keypad-row">
          <div class="btndiv col-xs-3" id="4-num-div">4</div>
          <div class="btndiv col-xs-3" id="5-num-div">5</div>
          <div class="btndiv col-xs-3" id="6-num-div">6</div>
          <div class="btndiv col-xs-3" id="subtract-op-div">-</div>
        </div>
        <div class="row keypad-row">
          <div class="btndiv col-xs-3" id="1-num-div">1</div>
          <div class="btndiv col-xs-3" id="2-num-div">2</div>
          <div class="btndiv col-xs-3" id="3-num-div">3</div>
          <div class="btndiv col-xs-3" id="sign-num-div">&#177;</div>
        </div>
        <div class="row keypad-row">
          <div class="btndiv col-xs-6" id="0-num-div">0</div>
          <div class="btndiv col-xs-3" id="point-num-div">.</div>
          <div class="btndiv col-xs-3" id="equals-op-div">=</div>

        </div>
      </div>
      <!-- calculator -->
    </div>

    <div class="row footer-row">
    </div>

  </div>
  <!--close container-->
  <!-- jQuery first, then Tether, then Bootstrap JS. -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js" integrity="sha384-THPy051/pYDQGanwU6poAc/hOdQxjnOEXzbT+OuUAFqNqFjL+4IGLBgCJC3ZOShY" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.2.0/js/tether.min.js" integrity="sha384-Plbmg8JY28KFelvJVai01l8WyZzrYWG825m+cZ0eDDS1f7d/js6ikvy1+X+guPIB" crossorigin="anonymous"></script>
  <!-- Latest compiled and minified JavaScript -->
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  <script>
    "use strict";
      //define globals
      var registerArray = [["0",""]];
      var maxLength = 8;

      //Complete the page layout and register a click handler
      $(document).ready(function() {
        //line each btndiv with a button that inherits its id
        $('.btndiv').each(function() {
          var arr = this.id;
          $(this).wrapInner('<button id="' + this.id.slice(0,this.id.length - 4) + '-button" class="btn btn-default"' + '"></button>');
        });
        //register a general button click handler
        $(".btn").click(function() {
          var pressed = this.id.split('-');
          switch (pressed[1]) {
            case "num":
                handleNumPress(pressed[0]);
              break;
            case "op":
                handleOpPress(pressed[0]);
              break;
            default:
                handleClear(pressed[0]);
          }
          updateDisplay();
        })
      })

      function handleNumPress(num) {
        var currReg = registerArray[registerArray.length - 1][0]

        //point
        if (num == "point") {
          //if it doesn't have a point, add one
          //either way, return
          if (currReg.indexOf(".") == -1) {
            registerArray[registerArray.length - 1][0] = currReg + ".";
          }
          return;
        }

        //sign
        if (num == "sign") {
          //remove a leading minus, or add one
          if (registerArray[registerArray.length - 1][0][0] == "-") {
            registerArray[registerArray.length - 1][0] = registerArray[registerArray.length - 1][0].substring(1);
          } else {
            registerArray[registerArray.length - 1][0] = "-" + registerArray[registerArray.length - 1][0];
          }
          return;
        }

        //digit
        if (registerArray[registerArray.length - 1][0] == "0") {
          registerArray[registerArray.length - 1][0] = num;
          return;
        }
        if (registerArray[registerArray.length - 1][0] == "-0") {
          registerArray[registerArray.length - 1][0] = "-" + num;
          return;
        }

        //still here? check the length and add the digit
        var digLen = currReg.length;
        if (currReg.indexOf(".") != -1) {digLen--;}
        if (currReg.indexOf("-") != -1) {digLen--;}
        if (digLen < maxLength) {
          registerArray[registerArray.length - 1][0] = currReg + num
        }
      }

      function handleOpPress(op) {
          //add the operator

          registerArray[registerArray.length - 1][1] = op;
          //if it was equals, call calculateNow
          if (op == "equals") {
            calculateNow();
          } else {
            registerArray.push(["0",""])
          }
      }

      function handleClear(type) {
        if (type == "ac") {
          registerArray = [["0",""]];
        } else {
          registerArray[registerArray.length - 1] = ["0",""];
        }
      }

      function updateDisplay() {
        $(".display-main").html(registerArray[registerArray.length - 1][0]);
        // console.log($(".display-main").html());
        var breadcrumbs = "";
        var opLookup = {"subtract":"-","add":"+","divide":"/","multiply":"x","":""}
        for (var i = 0; i < registerArray.length; i++) {
          breadcrumbs = breadcrumbs + " " + registerArray[i][0] + " " + opLookup[registerArray[i][1]];
        }
        $(".display-breadcrumbs").html(breadcrumbs);
      }

      function calculateNow() {
        var row = 0,
            result = deCode(registerArray[0][0]);
        while (registerArray[row][1] != "equals") {
          row++;
          var rharg = deCode(registerArray[row][0])
          switch (registerArray[row - 1][1]) {
            case "add":
              result += rharg;
              break;
            case "subtract":
            result -= rharg;
              break;
            case "multiply":
            result *= rharg;
              break;
            case "divide":
            result /= rharg;
              break;
          }
        }
        console.log(result);
        registerArray = [[enCode(result),""]]
      }

      function deCode(str) {
        return parseFloat(str);
      }

      function enCode(num) {
        var enCoded = num.toString();
        var limLen = maxLength;
        if (enCoded.indexOf("-") != -1) {limLen++;}
        if (enCoded.indexOf(".") != -1) {limLen++;}
        return enCoded.substring(0,limLen);
      }

      console.log(deCode("-123.23"));
      var test = enCode(-45.4)
      console.log(test + " " + typeof(test));
  </script>
</body>

</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console