css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

            
              <h1>Javascript Calculator</h1>
<div class="both-wrapper">
  <div class="calculator-wrapper">
    <div class="calculator-back">
      <div class="display-screen-wrapper">
        <div class="display-screen" id="screen"></div>
      </div>
      <div class="buttons">
        <div class="first-btns">
          <btn class="btn " id="one">1</btn>
          <btn class="btn " id="two">2</btn>
          <btn class="btn " id="three">3</btn>
          <btn class="btn " id="CE">CE</btn>
        </div>
        <div class="first-btns">
          <btn class="btn " id="four">4</btn>
          <btn class="btn " id="five">5</btn>
          <btn class="btn " id="six">6</btn>
          <btn class="btn " id="plus">+</btn>
        </div>
        <div class="first-btns">
          <btn class="btn " id="seven">7</btn>
          <btn class="btn " id="eight">8</btn>
          <btn class="btn " id="nine">9</btn>
          <btn class="btn " id="minus">-</btn>
        </div>
        <div class="first-btns">
          <btn class="btn " id="decimal">.</btn>
          <btn class="btn " id="zero">0</btn>
          <btn class="btn " id="divide">÷</btn>
          <btn class="btn " id="multiply">x</btn>
        </div>
        <div class="first-btns">
          <btn class="btn " id="equals">=</btn>
          <btn class="btn" id="advFeatures">Adv→</btn>
        </div>
      </div>
    </div>
  </div>
  <!-- This is where the new buttons begin-->
  <div class="adv-features-panel" id="advPanel">
    <div class="calculator-back">
      <div class="display-screen-wrapper">

      </div>
      <div class="buttons">
        <div class="first-btns">
          <btn class="btn " id="e">e</btn>
          <btn class="btn " id="ln">ln</btn>
           <btn class="btn " id="sqrt">√</btn>
          <btn class="btn " id="xsquared">x²</btn>
        </div>
        
        <div class="first-btns">
          
          <btn class="btn " id="log">log<sub>10</sub></btn>
          <btn class="btn " id="eToX">e<sup>x</sup></btn>
          <btn class="btn " id="cubeRoot"><sup>3</sup>√</btn>
          <btn class="btn " id="xCubed">x<sup>3</sup></btn>

        </div>
        
        <div class="first-btns">
          <btn class="btn " id="sin">sin</btn>
          <btn class="btn " id="cos">cos</btn>
           <btn class="btn " id="tan">tan</btn>
          
                    <btn class="btn " id="pi">pi</btn>

        </div>
        
                <div class="first-btns">
          <btn class="btn " id="asin">asin</btn>
          <btn class="btn " id="acos">acos</btn>
           <btn class="btn " id="atan">atan</btn>
          
                    <btn class="btn " id="abs">abs</btn>

        </div>
        
        <div >
          <input id="degRad" type="checkbox" data-toggle="toggle" data-height="75" data-width="300" data-on="Degrees" data-off="Radians">
          
                    

        </div>
        
        <div class="first-btns">
          <btn class="btn " id="quote">Inspirational Math Quote</btn>
          

        </div>

      </div>
    </div>
  </div>
</div>
<p class="footer-text"> Written and coded by <a href="https://jwolfgang.info" target="_blank">Jim C-Mikecz</a> 2018</p>
            
          
!
            
              body {
  background-color: #f0f0f0;
  font-family: 'Teko', sans-serif;
  font-size:2em;
  text-align:center;
}

.both-wrapper {
  display: -webkit-inline-box;
  display: -webkit-inline-flex;
  display: -ms-inline-flexbox;
  display: inline-flex;
  display: -moz-box;
}

 .footer-text {
  font-size: .5em;
  margin-top: 2%;
}

#advPanel {
  visibility:collapse;
  opacity: 0;
}

#advFeatures:hover{
  background-color:#ecd3b5;
}

h1 {
  margin: 1% auto;
}

#plus, #minus, #divide, #multiply, #decimal {
  background-color: white;
}

#plus:hover, #minus:hover, #divide:hover, #multiply:hover, #decimal:hover {
  background-color: #f0f0f0;
}

btn#advFeatures {
    width: 50%;
    background: bisque;
}

.calculator-wrapper {
  height: 100%;
}

.display-screen {
  width: 100%;
  height: 75px;
  background-color: #000;
  
}
.display-screen-wrapper {
  width:100%;
  text-align: right;
  height: 15%;
  
}
.calculator-back {
  width: 35%;
  background-color: #4b658e;
  margin: 0 auto;
  border-radius: 3%;
  border: 4px solid black;
  margin-top: 2%;
  box-shadow: 10px 10px 5px grey;
  width: 320px;
  

}

.first-btns {
  width: 100%;
  height: 15%;
  text-align: center;
  display: flex;
  justify-content: center;
  
}

#screen {
  color: white;
  background-color: #000;
  margin-right: 100px;
  overflow-x: auto;
}

.btn {
  width: 25%;
  border: 1.5px solid black;
  cursor: pointer;
  background-color: tomato;
  font-size: 1.25em;

}

.btn:hover {
  background-color: #e7391a;
}


#equals {
 width: 50%;
}

.adv-features-panel btn {
    background-color: initial;
    color: white;
}

#sin, #cos, #tan, #asin, #acos, #atan {
  background-color: tomato;
  color:black;
}

#sin:hover, #cos:hover, #tan:hover, #asin:hover, #acos:hover, #atan:hover {
  background-color: #e7391a;
}

.adv-features-panel btn:hover {
    background-color: #42587a;
}

.toggle-group .btn {
  width:auto;
}

btn#quote {
    width: 100%;
}

label.btn.btn-default.active.toggle-off {
    width: auto;
}
            
          
!
            
              $(document).ready(function() {
  let screenVal = $("#screen").html();

  function screenUpdate() {
    screenVal = $("#screen").html();
    console.log(`This is ${screenVal}`);
    console.log(`The eval is ${eval(screenVal)}`);
    $("#screen").html(screenVal);
  }

  function clearAll() {
    screenVal = "";
    $("#screen").html("");
  }
  /*These variables are for storing the button values in text, etc */
  var one = 1;
  var plus = $("#plus").html();
  var equals = $("#equals").html();

  console.log(one);
  $("#one").click(function() {
    $("#screen").html(screenVal + 1);
    screenUpdate();
  });

  $("#two").click(function() {
    $("#screen").html(screenVal + 2);
    screenUpdate();
  });

  $("#three").click(function() {
    $("#screen").html(screenVal + 3);
    screenUpdate();
  });

  $("#four").click(function() {
    $("#screen").html(screenVal + 4);
    screenUpdate();
  });

  $("#five").click(function() {
    $("#screen").html(screenVal + 5);
    screenUpdate();
  });

  $("#six").click(function() {
    $("#screen").html(screenVal + 6);
    screenUpdate();
  });

  $("#seven").click(function() {
    $("#screen").html(screenVal + 7);
    screenUpdate();
  });

  $("#eight").click(function() {
    $("#screen").html(screenVal + 8);
    screenUpdate();
  });

  $("#nine").click(function() {
    $("#screen").html(screenVal + 9);
    screenUpdate();
  });

  $("#zero").click(function() {
    $("#screen").html(screenVal + 0);
    screenUpdate();
  });

  $("#e").click(function() {
    $("#screen").html(screenVal + 2.71828182845);
    screenUpdate();
  });

  $("#pi").click(function() {
    $("#screen").html(screenVal + 3.14159265359);
    screenUpdate();
  });

  $("#decimal").click(function() {
    $("#screen").html(screenVal + ".");
    screenUpdate();
  });

  $("#plus").click(function() {
    $("#screen").html(screenVal + plus);
    screenUpdate();
  });

  $("#minus").click(function() {
    $("#screen").html(screenVal + "-");
    screenUpdate();
  });

  $("#divide").click(function() {
    $("#screen").html(screenVal + "/");
    screenUpdate();
  });

  $("#multiply").click(function() {
    $("#screen").html(screenVal + "*");
    screenUpdate();
  });

  $("#sqrt").click(function() {
    $("#screen").html(Math.sqrt(eval(screenVal)));
    screenUpdate();
  });

  $("#xsquared").click(function() {
    var pow = eval(screenVal);
    $("#screen").html(Math.pow(pow, 2));
    screenUpdate();
  });

  $("#xCubed").click(function() {
    var pow = eval(screenVal);
    $("#screen").html(Math.pow(pow, 3));
    screenUpdate();
  });

  $("#cubeRoot").click(function() {
    var pow = eval(screenVal);
    $("#screen").html(Math.cbrt(pow));
    screenUpdate();
  });

  $("#sin").click(function() {
    var pow = eval(screenVal);
    if ($('#degRad').prop( "checked" ) === false) {
    $("#screen").html(Math.sin(pow));
    screenUpdate();
      } else {
        pow = pow*Math.PI/180;
        $("#screen").html(Math.sin(pow));
    screenUpdate();
      }
  });

  $("#cos").click(function() {
    var pow = eval(screenVal);
    if ($('#degRad').prop( "checked" ) === false) {
    $("#screen").html(Math.cos(pow));
    screenUpdate();
    } else {
      pow = pow*Math.PI/180;
        $("#screen").html(Math.cos(pow));
    screenUpdate();
    }
  });

  $("#tan").click(function() {
    var pow = eval(screenVal);
    if ($('#degRad').prop( "checked" ) === false) {
    $("#screen").html(Math.tan(pow));
    screenUpdate();
    } else {
      pow = pow*Math.PI/180;
        $("#screen").html(Math.tan(pow));
    screenUpdate();
    }
  });
  
    $("#asin").click(function() {
    var pow = eval(screenVal);
      if ($('#degRad').prop( "checked" ) === false) {
    $("#screen").html(Math.asin(pow));
    screenUpdate();
      } else {
        pow = Math.asin(pow)*180/Math.PI;
        $("#screen").html(pow);
    screenUpdate();
      }
  });

  $("#acos").click(function() {
    var pow = eval(screenVal);
    if ($('#degRad').prop( "checked" ) === false) {
    $("#screen").html(Math.acos(pow));
    screenUpdate();
    } else {
      pow = Math.acos(pow)*180/Math.PI;
        $("#screen").html(pow);
    screenUpdate();
    }
  });

  $("#atan").click(function() {
    var pow = eval(screenVal);
    if ($('#degRad').prop( "checked" ) === false) {
    $("#screen").html(Math.atan(pow));
    screenUpdate();
    } else {
      pow = Math.atan(pow)*180/Math.PI;
        $("#screen").html(pow);
    screenUpdate();
    }
  });

  $("#ln").click(function() {
    var pow = eval(screenVal);
    $("#screen").html(Math.log(pow));
    screenUpdate();
  });

  $("#log").click(function() {
    var pow = eval(screenVal);
    $("#screen").html(Math.log10(pow));
    screenUpdate();
  });
  
    $("#abs").click(function() {
    var pow = eval(screenVal);
    $("#screen").html(Math.abs(pow));
    screenUpdate();
  });

  $("#eToX").click(function() {
    var pow = eval(screenVal);
    $("#screen").html(Math.exp(pow));
    screenUpdate();
  });

  var i = 0;
  var quoteArray = [
      '"Numbers rule the universe." -Pythagoras',
      '"Wherever there is number, there is beauty." -Proclus', '"A lot of music is mathematics. It\'s balance." -Mel Brooks','"To those who ask what the infinitely small quantity in mathematics is, we answer that it is actually zero." -Leonhard Euler'];
  $("#quote").on("click", function() {
    
    $("#screen").css("font-size", "0.7em");
    $("#screen").html(quoteArray[i]);    
    i++;
    console.log(i);
    if (i == quoteArray.length) {
      i = 0;
    }
    screenUpdate();
  });
  
  
  var p = $('#degRad').prop( "checked" );

  console.log(Math.sin());
  
    
  $("#equals").click(function() {
    $("#screen").html(eval(screenVal));
    screenUpdate();
  });

  $("#CE").click(function() {
    clearAll();
    $("#screen").css("font-size", "1em");
  });

  $("#advFeatures").click(function() {
    var visible = $("#advPanel").css("visibility");
    console.log("clicked; " + visible);
    if (visible === "collapse") {
      $("#advPanel").css("visibility", "visible");
      $("#advPanel").css("opacity", "1");

      $("#advPanel").css("transition", "opacity 1000ms");
    } else {
      $("#advPanel").css("visibility", "collapse");
      $("#advPanel").css("transition", "opacity 500ms");

      $("#advPanel").css("opacity", "0");

      $("#advPanel").css("transition", "visibility 100ms");
    }
  });
});

            
          
!
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.
Loading ..................

Console