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.

            
              <head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<div class="thatBtn addShadow" id="main">
  <div id="frame">
    <div id="window">
      <p class="text-right inputNr">
        <span id="result">&nbsp;0</span>
      </p>
    </div>
    <div id="bottomHalf">
    <p class="text-right bottomText">
      <span id="numbersAndMethods">&nbsp;</span>
    </p>
    </div>
    <!--           </div> -->

  </div>

  <div class="spaceBetween"></div>
  <div class="buttons">
    <div id="C" class="btn btn-danger aButton removeTop removeLeft"><span>C</span></div>
    <div id="del" class="btn btn-primary aButton removeTop" style="padding-top:2px;"><span style="font-size:20px;">↫</span></div>
    <div id="percent" class="btn btn-primary aButton removeTop"><span>%</span></div>
    <div id="divide" class="btn btn-warning aButton removeTop removeRight"><span>/</span></div>
    <div id="seven" class="btn btn-secondary aButton removeLeft"><span>7</span></div>
    <div id="eight" class="btn btn-secondary aButton"><span>8</span></div>
    <div id="nine" class="btn btn-secondary aButton"><span>9</span></div>
    <div id="times" class="btn btn-warning aButton removeRight"><span>x</span></div>
    <div id="four" class="btn btn-secondary aButton removeLeft"><span>4</span></div>
    <div id="five" class="btn btn-secondary aButton"><span>5</span></div>
    <div id="six" class="btn btn-secondary aButton"><span>6</span></div>
    <div id="minus" class="btn btn-warning aButton removeRight"><span>-</span></div>
    <div id="one" class="btn btn-secondary aButton removeLeft"><span>1</span></div>
    <div id="two" class="btn btn-secondary aButton"><span>2</span></div>
    <div id="three" class="btn btn-secondary aButton"><span>3</span></div>
    <div id="plus" class="btn btn-warning aButton removeRight"><span>+</span></div>
    <div id="specialButton" class="btn btn-secondary aButton removeBottom removeLeft"><span>0</span></div>
    <div id="stop" class="btn btn-secondary aButton removeBottom">.</div>
    <div id="equal" class="btn btn-success aButton removeBottom removeRight">=</div>
  </div>

</div>
            
          
!
            
              body{
  background-image: url(https://images.unsplash.com/photo-1453733190371-0a9bedd82893?ixlib=rb-0.3.5&s=01fea6a0a9b006c5ff5e3ae10a6e0c31&dpr=1&auto=format&fit=crop&w=1000&q=80&cs=tinysrgb);
background-repeat: no-repeat;
background-size: cover;
}

#main{
  margin-left: auto;
  margin-right: auto;
  margin-top: 50px;
  width: 249px;
  height: 350px;
  background-color: #404040;
  padding-top: 30px;
}

.addShadow{
  box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
}

#frame{
  width: 185px;
  height: 80px !important;
  background-color: white;
  padding: 2px;
  background-color: black;
/* /*   overflow: hidden; */ */
}
.spaceBetween{
  height: 20px;
  width: 100%;
/*   background: green; */
}
p {
  margin-top:0px!important;
}
.inputNr{
  font-size: 28px;
  overflow-x: scroll;
}
#window{
  width: 100%;
  height: 60%;
  background-color: white;
  padding-left:10px;
  padding-right: 10px;
  margin-bottom:0px;
  padding-bottom: 0px;
/*   overflow: auto; */
  
}
#bottomHalf{
  width: 181px;
  height: 40%;
  background-color: white;
  padding-left:10px;
  padding-right: 10px;
  margin-bottom:0px;
  padding-bottom: 0px;
  display: run-in;
  
}

.buttons{
  height: 200px;
  width: 100%;
/*   background-color: blue; */
}


.aButton{
  width: 41px;
  height: 35px;
/*   background-color: yellow; */
  margin: 3px;
  float: left;
  -webkit-box-shadow: 0px 0px 2px 1px rgba(41,41,41,1);
-moz-box-shadow: 0px 0px 2px 1px rgba(41,41,41,1);
box-shadow: 0px 0px 2px 1px rgba(41,41,41,1);
}

.removeLeft{
  margin-left: 1px;
}
.removeRight{
  margin-right: 0px;
}
.removeTop{
  margin-top: 0px;
}
.removeBottom{
  margin-bottom: 0px;
} 
#specialButton{
  width: 88px!important;
/*   background-color: green; */
}
#result{
 font-size: 26px;
  line-height: inherit;
}

.underInput{
  display: inline-block;
  padding-top: 0px;
  margin-top: 0px;
}

.thatBtn{
  width: 185px;
  height: 256px;
  margin-left: auto;
  margin-right: auto;
  display: block;
  padding: 32px;
  border-radius: 5px;
}
.bottomText{
  display: inline;
  float: right;
  font-size: 13px;
}
            
          
!
            
              var result = " ";
var numbersAndMethods = " ";
var resultNumber = 0;
var temporaryNumber = "";
var place = 0;
var method = "none";
var pointUsed = 0;
var error = 0;

// ----- The inputs ----- // ----- They are added this way to enable the use of Cordova ----- //

$("#C").click(function() {
  useCalc("C");
});
$("#del").click(function() {
  useCalc("del");
});
$("#percent").click(function() {
  useCalc("%");
});
$("#divide").click(function() {
  useCalc("/");
});
$("#seven").click(function() {
  useCalc("7");
});
$("#eight").click(function() {
  useCalc("8");
});
$("#nine").click(function() {
  useCalc("9");
});
$("#times").click(function() {
  useCalc("*");
});
$("#four").click(function() {
  useCalc("4");
});
$("#five").click(function() {
  useCalc("5");
});
$("#six").click(function() {
  useCalc("6");
});
$("#minus").click(function() {
  useCalc("-");
});
$("#one").click(function() {
  useCalc("1");
});
$("#two").click(function() {
  useCalc("2");
});
$("#three").click(function() {
  useCalc("3");
});
$("#plus").click(function() {
  useCalc("+");
});
$("#specialButton").click(function() {
  useCalc("0");
});
$("#stop").click(function() {
  useCalc(".");
});
$("#equal").click(function() {
  useCalc("=");
});

// ----- JS Starts here // ----- Do not change above this line ----- //

function clearAll() {
  $("#result").text("0");
  result = " ";
  resultNumber = 0;
  $("#numbersAndMethods").text(" ");
  temporaryNumber = "";
  method = none;
  pointUsed = 0;
  error = 0;
  console.log("Running clearAll. pointUsed is now: " + pointUsed);
}

function updateView() {
  $("#numbersAndMethods").text(temporaryNumber);
}
function calcIt(theNumbers) {
  if ($.isNumeric(temporaryNumber[temporaryNumber.length - 1])) {
    $("#result").text(eval(temporaryNumber));
  } else {
    deleteLast();
    $("#result").text(eval(temporaryNumber));
  }
}
function deleteLast() {
  temporaryNumber = temporaryNumber.substring(0, temporaryNumber.length - 1);
  updateView();
}
// ----- Functions end here ----- // ----- They should work ----- //

function useCalc(symbol) {
  if (symbol === "C") {
    clearAll();
  }
  if (symbol === "del") {
    deleteLast();
  }
  console.log(temporaryNumber.length);
  if (temporaryNumber.length > 19 && (symbol != "C" || symbol != "del")) {
    $("#numbersAndMethods").text("Input limit reached!");
    error = 1;
    return;
  }
  if (temporaryNumber.length <= 19 && error === 1) {
    updateView();
    error = 0;
    return;
  }

  
  if (symbol === "=") {
    calcIt();
  }
 

  if (
    symbol === "." &&
    $.isNumeric(temporaryNumber[temporaryNumber.length - 1]) &&
    pointUsed === 0
  ) {
    temporaryNumber = temporaryNumber + symbol;
    updateView();
    pointUsed = 1;
  } else if (
    (symbol === "-" || symbol === ".") &&
    (temporaryNumber === "" ||
      (!$.isNumeric(temporaryNumber[temporaryNumber.length - 1]) &&
        pointUsed === 0))
  ) {
    if (symbol === ".") {
      temporaryNumber = temporaryNumber + "0.";
      updateView();
      pointUsed = 1;
    } else if (
      symbol === "-" &&
      (temporaryNumber[temporaryNumber.length - 1 != "-"] ||
        temporaryNumber === "")
    ) {
      temporaryNumber = temporaryNumber + "-";
    }
    updateView();
  }

  if (symbol >= 0 && symbol <= 9) {
    temporaryNumber = temporaryNumber + symbol;
    updateView();
  }
  if (
    (symbol == "%" ||
      symbol == "/" ||
      symbol == "*" ||
      symbol == "-" ||
      symbol == "+") &&
    $.isNumeric(temporaryNumber[temporaryNumber.length - 1])
  ) {
    calcIt();
    temporaryNumber = temporaryNumber + symbol;
    pointUsed = 0;
    updateView();
  }
  console.log(
    "Running useCalc with symbol: " + symbol + " pointUSed is: " + pointUsed
  );
}

            
          
!
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