Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML

              
                <div class="body">
	<div class="calc-body">
		<h2>JS X IIS</h2>
		<div class="display">
			<h3 class="disp_main">0</h3>
			<p class="disp_sub"></p>
		</div>
		<div class="buttons">
			<div class="ac">AC</div>
			<div class="ce">CE</div>
			<div class="divide">/</div>
			<div class="x">x</div>
			<div class="minus">-</div>
			<div class="plus">+</div>
			<div class="equals">=</div>
			<div class="n0">0</div>
			<div class="n1">1</div>
			<div class="n2">2</div>
			<div class="n3">3</div>
			<div class="n4">4</div>
			<div class="n5">5</div>
			<div class="n6">6</div>
			<div class="n7">7</div>
			<div class="n8">8</div>
			<div class="n9">9</div>
			<div class="dot">.</div>
		</div>
	</div>
	<div class="footer">
		<p>Created by Gabriel Mukobi. Visit <a href="http://gabrielmukobi.com/">gabrielmukobi.com</a></p>
	</div>
</div>
              
            
!

CSS

              
                * {
	margin: 0;
	padding: 0;
/* 	border: 1px solid rgba(0,0,255, 0.3); */
	text-align: center;
	color: white;
	font-family: 'Roboto', sans-serif;
}

body, html {
	width: 100%;
	height: 100%;
}

.body {
	position: relative;
	width: 100%;
	height: 100%;
	background-color: rgb(10,83,64);
}

.calc-body {
	background-color: rgb(30,30,30);
	width: 430px;
	height: 650px;
	position: absolute;
	left: 50%;
	top: 45%;
	transform: translate(-50%, -50%);
	border: 3px solid rgb(90, 20, 20);
	border-radius: 7%;
	box-shadow: 0px 15px 50px 15px  black, inset -3px -3px 15px 0px rgba(200,200,250,0.8);
}

.calc-body > h2 {
	margin: 10px;
	color: 
}

.display {
	height: 100px;
	background-color: #5e9562;
	margin: 20px;
	overflow: hidden;
	position: relative;
}

.disp_main {
	display: block;
	height: 40pt;
	text-align: right;
	font-size: 30pt;
	line-height: 40pt;
	font-family: 'Orbitron', sans-serif;
	overflow: hidden;
	position: absolute;
	top: 5px;
	right: 10px;
}

.disp_sub {
	font-size: 15pt;
	text-align: right;
	overflow: hidden;
	position: absolute;
	bottom: 10px;
	right: 10px;
}

.buttons {
	display: grid;
	grid-template-columns: 25% 25% 25% 25%;
	grid-template-rows: 20% 20% 20% 20% 20%;
	grid-template-areas:
		"ac ce divide x"
		"n7 n8 n9 minus"
		"n4 n5 n6 plus"
		"n1 n2 n3 equals"
		"n0 n0 dot equals";
	margin: 0 15px;
}

.buttons > * {
	padding: 22px;
	margin: 10px;
	background-color: rgba(100,100,100,0.5);
	border-radius: 10%;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0px 6px 0 0 rgb(90, 20, 20),
		inset 0px -4px 20px 1px rgba(150,150,150,0.8);
	font-size: 125%;
	transition: all 100ms;
}

.buttons > div:active {
	box-shadow: 0px 0px 0 0 rgb(90, 20, 20),
		inset 0px -6px 30px 5px rgba(150,150,150,0.8);
	transform: translate(0, 6px);
}

.ac {
	grid-area: ac;
}
.ce {
	grid-area: ce;
}
.divide {
	grid-area: divide;
}
.x {
	grid-area: x;
}
.minus {
	grid-area: minus;
}
.plus {
	grid-area: plus;
}
.equals {
	grid-area: equals;
}
.n0 {
	grid-area: n0;
}
.n1 {
	grid-area: n1;
}
.n2 {
	grid-area: n2;
}
.n3 {
	grid-area: n3;
}
.n4 {
	grid-area: n4;
}
.n5 {
	grid-area: n5;
}
.n6 {
	grid-area: n6;
}
.n7 {
	grid-area: n7;
}
.n8 {
	grid-area: n8;
}
.n9 {
	grid-area: n9;
}
.dot {
	grid-area: dot;
}

.footer {
	position: absolute;
	bottom: 5%;
	left: 50%;
	transform: translate(-50%, 0);
}
              
            
!

JS

              
                var main_display = "0";
var sub_display = "";
var ok_to_clear_main = false;

var operationChars = /[x\/\-+]/;

var setting_negative_number = false;

function clear_main_display() {
	main_display = "0";
	update_main_display_text();
}

function clear_sub_display() {
	sub_display = "";
	update_sub_display_text();
}

function update_main_display_text() {
	$(".disp_main").text(main_display);
}

function update_sub_display_text() {
	$(".disp_sub").text(sub_display);
}

function recalculate_variables() {
	main_display = $(".disp_main").text();
	sub_display = $(".disp_sub").text();
}

function add_text_to_main_display(text) {
	var previous = $(".disp_main").text();
	if(setting_negative_number) {
		setting_negative_number = false;
	}
	else if(previous.match(operationChars) || previous == "0" || ok_to_clear_main) {
		previous = "";
		ok_to_clear_main = false;
	}
	$(".disp_main").text(previous + text);
}

function set_main_display_text(text) {
	$(".disp_main").text(text);
}
function set_sub_display_text(text) {
	$(".disp_sub").text(text);
}

$(document).ready(function() {
	update_main_display_text();
});

function ac() {
	clear_main_display();
	clear_sub_display();
}

function ce() {
	clear_main_display();
}

function n0() { add_text_to_main_display("0"); }
function n1() { add_text_to_main_display("1"); }
function n2() { add_text_to_main_display("2"); }
function n3() { add_text_to_main_display("3"); }
function n4() { add_text_to_main_display("4"); }
function n5() { add_text_to_main_display("5"); }
function n6() { add_text_to_main_display("6"); }
function n7() { add_text_to_main_display("7"); }
function n8() { add_text_to_main_display("8"); }
function n9() { add_text_to_main_display("9"); }

function divide() {
	recalculate_variables();
	if(sub_display.match(operationChars)) {
		equals();
	}
	set_sub_display_text(main_display + "/");
	set_main_display_text("/");
}
function x() {
	recalculate_variables();
	if(sub_display.match(operationChars)) {
		equals();
	}
	set_sub_display_text(main_display + "x");
	set_main_display_text("x");
}
function minus() {
	recalculate_variables();
	if(sub_display.match(operationChars)) {
		equals();
	}
	
	if(sub_display == "") {
		setting_negative_number = true;
		//set_sub_display_text("-");
	}
	else {
		set_sub_display_text(main_display + "-");
	}
	set_main_display_text("-");
}
function plus() {
	recalculate_variables();
	if(sub_display.match(operationChars)) {
		equals();
	}
	set_sub_display_text(main_display + "+");
	set_main_display_text("+");
}

function equals() {
	recalculate_variables();
	console.log(main_display);
	console.log(main_display.charAt(main_display.length - 1).match(operationChars) !== null);
	if(main_display.charAt(main_display.length - 1).match(operationChars) !== null) {
		main_display = sub_display.substring(0,sub_display.length - 1);
		console.log("new: " + main_display);
	}
	else {
		var left = parseFloat(sub_display.substring(0,sub_display.length - 1));
		var right = parseFloat(main_display);
		var total;
		if(sub_display.charAt(sub_display.length - 1) === "/") {
			total = Math.round(left / right * 10000000000) / 10000000000;
		}
		else if(sub_display.charAt(sub_display.length - 1) === "x") {
			total = Math.round(left * right * 10000000000) / 10000000000;
		}
		else if(sub_display.charAt(sub_display.length - 1) === "-") {
			total = left - right;
		}
		else if(sub_display.charAt(sub_display.length - 1) === "+") {
			total = left + right;
		}
		else {
			total = main_display;
		}
		main_display = String(total);
	}
	set_sub_display_text("=" + main_display);
	set_main_display_text(main_display);
	ok_to_clear_main = true;
}

$(".ac").click(ac);

$(".ce").click(ce);

$(".n0").click(n0);
$(".n1").click(n1);
$(".n2").click(n2);
$(".n3").click(n3);
$(".n4").click(n4);
$(".n5").click(n5);
$(".n6").click(n6);
$(".n7").click(n7);
$(".n8").click(n8);
$(".n9").click(n9);

$(".dot").click(function() {
	recalculate_variables();
	console.log(main_display.indexOf("."));
	
	if(main_display.indexOf(".") === -1) {
		 add_text_to_main_display(".");
	}
	recalculate_variables();
	console.log(main_display);
});

$(".plus").click(plus);
$(".minus").click(minus);
$(".divide").click(divide);
$(".x").click(x);
$(".equals").click(equals);
              
            
!
999px

Console