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.

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

<div class = "body">
  <div class = "container-fluid">

  <div class = "calculator">
    <div class = "model">
      <h4 class = "model" id = "casio">Casio</h4>   
    </div> <!--ends casio-->
    <div class= "screen">
      
      <div class ="row" id = "result">
        <h4>Screen</h4>
      </div> <!-- ends screen-->    
      
      <div class = "buttons">

        <div class = "row">  <!-- top row of operators-->
          <button class = "btn btn-danger" id = "ac">AC</button>

           <button class = "btn btn-danger" id = "ce">CE</button>

          <button class = "btn btn-primary" id = "percentage">%</button>  

           <button class = "btn btn-primary" id = "divide" >/</button>  
        </div> <!-- ends top row of operators-->  

        <div class = "row">  <!-- top row of numbers-->
        <button class = "btn btn-primary" id = "seven">7</button>

         <button class = "btn btn-primary" id = "eight">8</button>

        <button class = "btn btn-primary" id = "nine" >9</button>  

         <button class = "btn btn-primary" id = "multiply" >x</button>  
        </div> <!-- ends top row of numbers-->  

        <div class = "row"> <!-- middle row of numbers-->
          <button class = "btn btn-primary" id = "four">4</button>

          <button class = "btn btn-primary" id = "five">5</button>

          <button class = "btn btn-primary" id = "six" >6</button>

          <button class = "btn btn-primary" id = "subtract" >-</button>        
        </div> <!-- ends middle row-->  

        <div class = "row"> <!-- bottom row of numbers-->
          <button class = "btn btn-primary" id = "one">1</button>

          <button class = "btn btn-primary" id = "two">2</button>

          <button class = "btn btn-primary" id = "three" >3</button>

          <button class = "btn btn-primary" id = "add" >+</button>             
        </div> <!-- ends ends bottom row of numbers-->        

              <div class = "row" id = "bottom"> <!-- bottom row-->
          <button class = "btn btn-primary" id = "zero">0</button>

          <button class = "btn btn-primary" id = "decimal">.</button>

          <button class = "btn btn-primary" id = "equals" >=</button>      


         </div> <!-- ends ends bottom row-->          

      </div> <!-- ends all buttons-->

  </div> <!--end calculator-->
    </div><!-- ends container fluid-->
</div> <!-- ends body -->
            
          
!
            
              

.body{
 
background: url("https://static.pexels.com/photos/230776/pexels-photo-230776.jpeg");
  background-size: cover;
}
.container-fluid{
  padding: 10em 30em 10em 20em;
}

.calculator {
  background-color: rgba(21,13,63,1);
  width: 300px;


  box-shadow: 5px 5px 5px black;
  padding: 3em;
  margin: 0em 0em 0em 0em;
  border-radius: 10px;
}
#casio{color: white;
margin: 0px 0px 10px -10px;
}

#result {
  background-color: rgba(194, 249, 200, 1);
  margin: 0px 0px 5px -10px;
  text-align: right;
  font-family: Orbitron;
  width: 105%;
  padding: 5px;
}


.buttons{padding: 2px 2px 2px 2px;
}

.btn{margin: 2px;
height: 50px;
width: 50px;
box-shadow: 1px 1px 0.5px ;
padding: 2px;}

#add {height: 105px;

float: right;
}
#bottom {position: absolute;

margin: -55px 0px 0px -15px;}

            
          
!
            
              $(document).ready(function(){

var sum = 0;
  var num = 0;
var operator = "start";
  var lastVal = "";
  var displayNum = "";
  var decimal = false;


$("#result").html(sum);
  
  
 function operation(){
   
   //need to change to display Num, not num
    if(operator == "+") {sum = sum+displayNum;}
  else if (operator == "-") {sum = sum-displayNum;}
  else if (operator =="*") {
      
      if(sum ==0){sum = 1*displayNum;}
      else {sum = sum*displayNum;}
  }
  else if (operator == "/") {
      if(sum ==0){sum = displayNum/1;}
      else {sum = sum/displayNum;}
  }    
    else if (operator =="="){
      sum = sum;
    }
    else {console.log("error");}
   
   $("#result").html(sum);
   displayNum = sum;
 
 };
  
  function isFirstNumber(){
    if(operator=="="){
      displayNum = num;
      lastVal = num;
      $("#result").html(displayNum);
    }
    
    else if(decimal === true){
      console.log(typeof displayNum);
   displayNum = displayNum+num/10;
    
     displayNum = Number(displayNum);
  
      $("#result").html(displayNum);
      
    console.log(displayNum);
      
      decimal = false;
    }
    
 else  if(Number.isInteger(lastVal)){
    displayNum = Number(String(lastVal) +String(num));

    $("#result").html(displayNum);
    lastVal = displayNum;
    }
  
  else{  
  displayNum = num;
    lastVal = num;
    $("#result").html(displayNum);
  }
  };

$("#zero").click(function(){
  num = 0;  
  isFirstNumber();
}); //ends one button  
$("#one").click(function(){
  num = 1;  
  isFirstNumber();
}); //ends one button
  
  $("#two").click(function(){
  num = 2;
    isFirstNumber();
}); //ends two button

    $("#three").click(function(){
  num = 3;
    isFirstNumber();
}); //ends three button
  
    $("#four").click(function(){
  num = 4;
    isFirstNumber();
}); //ends four button
  
    $("#five").click(function(){
  num = 5;
    isFirstNumber();
}); //ends five button
  
      $("#six").click(function(){
  num = 6;
    isFirstNumber();
}); //ends six button
  
      $("#seven").click(function(){
  num = 7;
    isFirstNumber();
}); //ends seven button
  
      $("#eight").click(function(){
  num = 8;
    isFirstNumber();
}); //ends eight button
  
      $("#nine").click(function(){
  num = 9;
    isFirstNumber();
}); //ends nine button
  
  // functions & operators
      //AC clear function
      $("#ac").click(function(){
  operator = "start";
        lastVal = 0;
        displayNum = 0;
        sum = 0; 
        decimal = false;
        $("#result").html(sum);
}); //ends AC clear button
  
//CE clear function

  /*$("#ce").click(function(){
     if(Number.isInteger(lastVal)){
        displayNum = parseInt(String(displayNum).slice(0,-1));
       $("#result").html(displayNum);
     }*/
 
  
   $("#ce").click(function(){
  operator = "start";
        lastVal = 0;
        displayNum = 0;
        sum = 0; 
     decimal = false;
        $("#result").html(sum);

   }); //ends CE clear button
  
  //percentage button
   $("#percentage").click(function(){
    displayNum = displayNum/100;

    console.log(displayNum);
    $("#result").html(displayNum); 
   });
  //ends percentage button
  
  //Addition button function
    $("#add").click(function(){
if(operator == "start"){operator = "+";}

      else{operator = operator;}
        operation();
      operator = "+"      
      lastVal = "+";
      console.log(operator);
}); //ends addition button
  
  //subtraction button function
      $("#subtract").click(function(){

if(operator == "start"){operator = "-";}

        else{operator = operator;}
        operation();
        operator = "-";        
        lastVal="-";
        console.log(operator);
}); //ends sutract button
  
    //multiply button function
      $("#multiply").click(function(){
if(operator == "start"){operator = "*";}
       
        else{operator = operator;}
        operation();
        operator = "*";
      lastVal="*";
        console.log(operator);
}); //ends multiply button
  
    //divide button function
      $("#divide").click(function(){
if(operator == "start"){operator = "/";}
    
        else{operator = operator;}
        console.log(operator);
        operation();
        operator = "/";
        lastVal="/";        

}); //ends divide button
  
  
  //decimal button
  $("#decimal").click(function(){
  decimal =true;

    
    if(Number.isInteger(lastVal)){

      
      console.log(displayNum);
      $("#result").html(String(displayNum)+".");
    };
      
});//ends decimal button
  
  //equals button
  $("#equals").click(function(){
    operation();
    operator = "=";
    console.log(sum);

  }); //ends equals button
  
});//ends get ready function
            
          
!
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