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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet">

<header class="text-center">
  <h1>jQuery Calculator</h1>
  <h3> By BERTINI Nickolas</h3>
</header>
<hr>

<div class="calculator container-fluid ">
  <div id="calcOutput" class="text-center">
    <span id="steps">0</span>
  </div>
  <div id="keyboard">
    <div class="row">
      <a class="btn btn-danger col" id="deleteAll">AC</a>
      <a class="btn btn-danger col" id="backOne">CE</a>
      <a class="btn btn-primary col" id="%">%</a>
      <a class="btn btn-primary col" id="/">/</a>      
    </div>
        <div class="row">
      <a class="btn btn-primary col num" id="7">7</a>
      <a class="btn btn-primary col num" id="8">8</a>
      <a class="btn btn-primary col num" id="9">9</a>
      <a class="btn btn-primary col" id="*">*</a>      
    </div>
        <div class="row">
      <a class="btn btn-primary col num" id="4">4</a>
      <a class="btn btn-primary col num" id="5">5</a>
      <a class="btn btn-primary col num" id="6">6</a>
      <a class="btn btn-primary col" id="-">-</a>      
    </div>
        <div class="row">
      <a class="btn btn-primary col num" id="1">1</a>
      <a class="btn btn-primary col num" id="2">2</a>
      <a class="btn btn-primary col num" id="3">3</a>
      <a class="btn btn-primary col" id="+">+</a>      
    </div>
        <div class="row">
          <div class="col-6 borderZero">
            <a class="btn btn-primary num col zero" id="0">0</a>
          </div>
            <a class="btn btn-primary col num" id=".">.</a>
            <a class="btn btn-primary col" id="=">=</a>    
    </div>

  </div>
</div>
              
            
!

CSS

              
                html, body {
  font-family: "Oswald";
background: #e1eec3;  /* fallback for old browsers */
background: -webkit-linear-gradient(to top, #f05053, #e1eec3);  /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to top, #f05053, #e1eec3); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
  height:100vh;
}

header {
  padding-top:30px;
}

.calculator {
  width: 20vw;
  min-width: 300px;
  padding-top:10px;
  background-color: black;
  border-radius:5px;
  margin-bottom: 50px;
  
  
  
}

#calcOutput {
  height:10vh;
  border: solid 2px black;
  font-size: 2em;
  display:flex;
  justify-content:flex-end;
  align-items:center;
  margin-top: 20px;
  margin-bottom:20px;
  background-color:white;
  border-radius:5px;
  padding-right:5px;
  
}

#keyboard {
    ;
}

.btn {
  height: 50px;
  margin: 5px;
  border:none;
  padding:3px;
  font-size: 1.5em;
  
}

.num{
  background-color: lightblue;
}

.borderZero{
  padding-left:1px;
  padding-right:10px;
}
              
            
!

JS

              
                $(document).ready(function() {
  var inputs = [];
  var totalString;
  var operators=["+","-","*","/","%"];
  
  //Add value and check validations
  function getValue (input) {
    // Check for don't start with an operator
    if(inputs.length === 0 && operators.includes(input)) {
      console.log("start with operator");
    // Check for double operator
    } else if (operators.includes(inputs[inputs.length-1]) && operators.includes(input)) {
      console.log("double operator");
    // Check for double "."
    } else if (inputs[inputs.length-1] === "." && input === ".") {
      console.log("double ..");
    } else {
      inputs.push(input);
      update();
    }
  };
  function getTotal() {
    totalString = inputs.join("");
    $("#steps").html(eval(totalString));
  };
  
  function update() {
  totalString = inputs.join("");
  $("#steps").html(totalString);
    console.log(inputs)
    console.log(totalString);    
  };
  
  $("a").on("click", function() {
    
    if(this.id === "deleteAll") {
      inputs = [];
      update();
    } else if (this.id === "backOne") {
      inputs.pop();
      update();
    } else if (this.id === "=") {
      getTotal();
    } else {
      getValue(this.id);
    }    
  });
});
              
            
!
999px

Console