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.

            
              <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>
            
          
!
            
              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;
}
            
          
!
            
              $(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
🕑 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.

Console