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

Packages

Add 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 or require. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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.

            
              <!DOCTYPE html>
<html>
<head>
<meta charset ="utf-8">
<meta name="viewport" content="width = device-width, initial-scale =1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="Calculator.js"></script>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Rajdhani" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Quicksand" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"></head>
<link href="Calculator.css" rel="stylesheet">
</head>
<body>
<div class="content">
<table>
<tr>
<td class="display" id="expressionDisplay" colspan="4"></td>
</tr>
<tr>
<td class="display" id="operandDisplay"colspan="4"></td>
</tr>
<tr>
 <td  class="buttonLeft"><button id="AC" class="buttonSquare">AC</button></td>
 <td ><button id="CE" class="buttonSquare">CE</button></td>
 <td ><button id="+/-" class="buttonSquare">+/-</button></td>
 <td class="buttonRight"><button id="/" class="operatorSquare">÷</button></td>
</tr>
<tr>
 <td class="buttonLeft"><button id="7" class="buttonSquare">7</button></td>
 <td ><button id="8" class="buttonSquare">8</button></td>
 <td ><button id="9" class="buttonSquare">9</button></td>
 <td class="buttonRight"><button id="x" class="operatorSquare">x</button></td>
</tr>
<tr>
 <td class="buttonLeft"><button id="4" class="buttonSquare">4</button></td>
 <td ><button id="5"class="buttonSquare ">5</button></td>
 <td ><button id="6"class="buttonSquare">6</button></td>
 <td class="buttonRight" ><button id="-"class="operatorSquare">-</button></td>
</tr>
<tr>
 <td class ="buttonLeft"><button id="1" class="buttonSquare">1</button></td>
 <td ><button id="2" class="buttonSquare">2</button></td>
 <td ><button id="3" class="buttonSquare">3</button></td>
 <td class="buttonRight" ><button id="+" class="operatorSquare">+</button></td>
</tr>
<tr>
 <td class="buttonBottom" style="border-left-width:0px"><button id="0" class="buttonSquare" >0</button></td>
 <td class="buttonBottom"><button id="%" class="buttonSquare">%</button></td>
 <td class="buttonBottom"><button id="." class="buttonSquare">.</button></td>
 <td class="buttonBottom" style="border-right-width:0px"><button id="=" class="operatorSquare">=</button></td>
</tr>
</table>
</div>
<p style="text-align:center"><i class="fa fa-heart" aria-hidden="true"></i></p>
<p style="text-align:center"><a href="https://github.com/abhinav-m">Abhinav Mishra</a></p>
<p style="text-align:center"><a href="https://github.com/abhinav-m">अभिनव मिश्रा</a></p>
</body>
</html>
            
          
!
            
              p{
		font-family: 'Rajdhani', sans-serif;
		font-size:1.2em;

}
a:link{
	text-decoration:none;

}
.fa-heart{
	color:red;
}
.buttonSquare{
	width:100px;
	height:100px;
}


.operatorSquare{
	width:100px;
	height:100px;
	background-color:#ffae19;
	color:white;
}

.content{
	display:flex;
	justify-content: center;
	margin-top:5%;
	margin-bottom:2%;

}

table{
		border-collapse:collapse;
		
}

button{
	font-family: 'Quicksand', sans-serif;
}

td{
	margin:0;
	padding:0;
	border-style:solid;
	border-width:0.2px 0.2px 0.2px 0.2px;
	

}

td:focus{
	border-width:1px 1px 1px 1px;
}


.buttonLeft{
	border-style:solid;
	border-width:0.2px 0.2px 0.2px 0px;
}

.buttonRight{
	border-style:solid;
	border-width:0.2px 0 0.2px 0.2px;
}

.buttonBottom{
	border-style:solid;
	border-width:0.2px 0.2px 0px 0.2px;
}

.buttonTop{
	border-style:solid;
	border-width:0px 0.2px 0.2px 0.2px;
}


button{
	margin:0;
	border:0;
	padding:0;font-size:1.5em;
}

.display{
	width:100%;
	height:75px;
	background-color:black;
	color:white;
	font-size:1em; 
	padding:2%;
	text-align:right;
}

#expressionDisplay{
	color:white;
	border:none;
	font-size:1em;
}


#operandDisplay{
	color:white;
	border:none;
	font-size:2em;
}

button:hover{
  cursor:cell;
  background-color:white;
  color:black;
}
            
          
!
            
              $(document).ready(function (){
var curExp;
var curOperand;
var isDecimal;
var isNegative;
var expressionDisplay;
var operandDisplay;
var operatorExists;
var isComputed;
setOnClick();
setDefault();
clearScreen();

}	);

function setDefault()
{ 
	curOperand = "";
	curExp  = "";
	isDecimal = false;
	isNegative = false;  
	expressionDisplay = document.getElementById("expressionDisplay");
	operandDisplay = document.getElementById("operandDisplay");
	operatorExists = false;
	isComputed = false;
}

function clearScreen(){
  expressionDisplay.innerHTML = "";
  operandDisplay.innerHTML = "";
}

function setExpDisplay(){
 expressionDisplay.innerHTML = curExp;
}

function setOperandDisplay(){
 operandDisplay.innerHTML = curOperand;
}

function setOnClick()
{
	//Operators
	document.getElementById("AC").onclick = function() {compute(this.id)};
	document.getElementById("+/-").onclick = function() {compute(this.id)};
	document.getElementById("%").onclick = function() {compute(this.id)};
	document.getElementById("/").onclick = function() {compute(this.id)};
	document.getElementById("-").onclick = function() {compute(this.id)};
    document.getElementById("+").onclick = function() {compute(this.id)};
	document.getElementById(".").onclick = function() {compute(this.id)};
	document.getElementById("x").onclick = function() {compute(this.id)};
	document.getElementById("=").onclick = function() {compute(this.id)};
	document.getElementById("CE").onclick = function() {compute(this.id)};
    //Operands
	document.getElementById("1").onclick = function() {compute(this.id)};
    document.getElementById("2").onclick = function() {compute(this.id)};
	document.getElementById("3").onclick = function() {compute(this.id)};
	document.getElementById("4").onclick = function() {compute(this.id)};
    document.getElementById("5").onclick = function() {compute(this.id)};
	document.getElementById("6").onclick = function() {compute(this.id)};
	document.getElementById("7").onclick = function() {compute(this.id)};
    document.getElementById("8").onclick = function() {compute(this.id)};
    document.getElementById("9").onclick = function() {compute(this.id)};
    document.getElementById("0").onclick = function() {compute(this.id)};
}

function compute(pressedKey)
{
	switch(pressedKey)
	{
		case "0":
		case "1":
		case "2":
		case "3":
		case "4":
		case "5":
		case "6":
		case "7":
		case "8":
		case "9":
		case "0":
		case ".":
		operandPressed(pressedKey);
		break;
		case "/":
		case "+":
		case "-":
		case "x":
		case "+/-":
		operatorPressed(pressedKey);
		break;
		case "=":
		calculate();
		break;
		case "AC":
		setDefault();
		clearScreen();
		break;
		case "%":
		makePercent();
		break;
		case "CE":
		clearOperand();
		break;
		
	}
}

/* If operand is pressed, wait till operator
is pressed to get value of complete operand */

function operandPressed(keyPressed)
{
    if(isComputed)
  	setDefault();
  	
 if(curOperand=="")
 {
  if(keyPressed=="."&&isDecimal==false)
  {
   curOperand="0.";
   isDecimal = true;
  }
  else
  curOperand=keyPressed;
 }
 else
 {
  if(!isDecimal&&keyPressed == ".")
  {
  curOperand+=keyPressed;
  isDecimal = true;
  }
  else if(keyPressed!=".")
  curOperand+=keyPressed;
 }
 setOperandDisplay();
  operatorExists = false;
}

/* If operator is pressed we get three conditions:
   >Unary +/- (Make the number negative or positive).
   >Binary Operator pressed , current operand is complete, wait for next operand's input
   >If currently there exists an operator at the end of the current expression, don't take any more operator input! */

function operatorPressed(keyPressed)
{

if(!operatorExists)
{
 if(isComputed)
 {
 	curExp = "";
 	isComputed = false;
 }
 if(keyPressed=="+/-")
 {
  
  if(!isNegative)
  {
  curOperand = "-"+curOperand;
  isNegative = true;
  }
  else{
  curOperand = curOperand.slice(1);
  isNegative = false;
  }
setOperandDisplay();
 }
 else{
 	if(isNegative)
 	curExp += "("+curOperand+")"+ keyPressed;
    else
 	curExp += curOperand + keyPressed;
    curOperand = "";
    isNegative = false;
    isDecimal = false;
    operatorExists = true;
 }
 setExpDisplay();
 setOperandDisplay();
}

}

function isOperator(val){
 return(val=="+"||val=="-"||val=="x"||val=="/"||val=="+/-");
}

function calculate()
{
  if(!isComputed)
  {
	var evalExpression;
	if(isNegative)
	curExp += "("+curOperand+")";
    else
	curExp = curExp + curOperand;
     evalExpression = curExp.replace(/x/g,"*");
	curOperand = eval(evalExpression);
	curOperand = curOperand+"";
	curExp = curExp + "="+curOperand;

	//Check if evaluated operand is negative.
	if(curOperand.charAt(0)=="-")
    isNegative = true;
    else
    isNegative = false;
	//Check if evaluated operand is a decimal.
	if(curOperand.indexOf(".")>-1)
	isDecimal = true;
    else
    isDecimal = false;

	setExpDisplay();
	setOperandDisplay();
	isComputed = true;
  }

}


function makePercent()
{
	var numberOperand;
	if(curOperand!="")
	{
      numberOperand = parseFloat(curOperand);
      numberOperand = numberOperand / 100;
      curOperand = "" + numberOperand;
      if(curOperand.indexOf(".")>-1)
      	isDecimal = true;
	}
	setOperandDisplay();	
}

function clearOperand(){
	if(isComputed)
	setDefault();
    else
    {
	curOperand = "";
	isNegative = false;
	isDecimal = false;
	}
	setOperandDisplay();
	setExpDisplay();
}




 

            
          
!
999px

Console