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 lang="en">
	<!-- EDIT HEAD INFO INSIDE CODEPEN PREFS -->
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">

		<link href="https://fonts.googleapis.com/css?family=Roboto:100,300" rel="stylesheet">
		<link rel="stylesheet" href="styles.css">
	</head>
	<body class="">
		<div class="wrapper">
			<div class="left-cell">
			</div>

			<div class="calculator">

				<!-- TOP ICON BAR -->
				<div class="nested-1 top-bar">
					<div class="flight-modus"><img src="http://i63.tinypic.com/sebv9j.png" alt="flight mode">
						&nbsp;
						<img src="http://i67.tinypic.com/5zqf4k.png" alt="wifi signal at full strength"></div>
					<div id="time">- : -</div>
					<div class="charge-status">96% <img src="http://i67.tinypic.com/30ldxtx.png" alt="battery at near full charge"></div>
				</div>

				<!-- RESULTS BOX -->
				<div class="nested-2 result">
				<div id="logNumber">0</div>
				</div>

				<!-- DIGITS AND OPERATION KEYS -->
				<div class="nested-3" id="pointer">
					<div class="operations bg-grey" id="clear">C</div>
					<div class="operations bg-grey" id="posNeg">+/-</div>
					<div class="operations bg-grey" id="percent">%</div>
					<div id="7">7</div>
					<div id="8">8</div>
					<div id="9">9</div>
					<div id="4">4</div>
					<div id="5">5</div>
					<div id="6">6</div>
					<div id="1">1</div>
					<div id="2">2</div>
					<div id="3">3</div>
					<div class="zero" id="0">0</div>
					<div id="dot"><b>.</b></div>
					<div class="operations bg-grey op-right" id="divide">&#247;</div>
					<div class="op-right"id="multiply">&#215;</div>
					<div class="op-right" id="minus">-</div>
					<div class="op-right" id="plus">+</div>
					<div class="op-right" id="result">=</div>
				</div>

			</div>
			<div class="right-cell">
				<div class="side-text">
					<p><a href="https://codepen.io/chrisjuchtmans/pens/public/" target="_blank">VIEW ALL MY PENS</a></p>
					<p>Powered by <a href="https://www.amdoren.com" target="_blank">Amdoren</a></p>
				</div>
			</div>
		</div>
	</body>
</html>

            
          
!
            
              html{
	font-size: 20px;
}

.wrapper{
	display:grid;
	grid-template-columns: 1.2fr 1fr 1.2fr;
	grid-auto-rows: minmax(700px, auto);
}

.wrapper > div{
	padding: 0;
}
/*
=== TOP ICON BAR ===
*/
.nested-1{
	display:grid;
	grid-template-columns: repeat(3, 1fr);
	justify-items: center;
}
.nested-1 > div{
	font-family: "Roboto", sans-serif;
	font-size: 0.6rem;
	color: white;
}

	.top-bar{
	padding-top: 0.3rem;
	}

	.flight-modus{
		justify-self:start;
		padding-left: 0.3rem;
	}

	.charge-status{
		justify-self:end;
		padding-right: 0.3rem;
	}

	/*
	=== RESULTS BOX ===
	*/

	.nested-2{
	display: grid;
	grid-auto-rows: minmax(200px, auto);
	justify-items: end;
}
	.nested-2 > div{
		font-family: "Roboto", sans-serif;
		font-size: 4rem;
		font-weight: lighter;
		color: white;
		padding-left: 0.2rem;
		padding-right: 0.2rem;
		align-self: end;
	}

	/*
	=== DIGITS AND FUNCTION KEYS ===
	*/

.nested-3 {
	display: grid;
	grid-template-columns:repeat(4, 1fr);
	grid-template-rows:repeat(5, 1fr);
	/*justify-items: center;*/
	font-size: 2.2rem;
	color: black;
	background: #888;
	grid-gap: 1px;
	font-family: "Roboto", sans-serif;
	font-weight: lighter;
	/*padding: 1rem;*/
}

#pointer{cursor: pointer;}

/* APPLY FLEXBOX INSIDE GRID */
.nested-3 > div{
	background: #ddd;
	display: flex;
	justify-content: center;
	align-items: center;
	padding: 1.3rem;
}
	.operations{
		font-size: 1.5rem;
		/*padding: 1.3rem;  ==> old. this is set in FLEX above */
	}

.nested-3 > .op-right {
	grid-column-start: 4;
	grid-row-start: 1;
	background: #fd8a0d;
	color: white;
}

.nested-3 > .op-right+.op-right {
	grid-row-start: 2;
}

.nested-3 > .op-right+.op-right+.op-right {
	grid-row-start: 3;
}

.nested-3 > .op-right+.op-right+.op-right+.op-right {
	grid-row-start: 4;
}

.nested-3 > .op-right+.op-right+.op-right+.op-right+.op-right {
	grid-row-start: 5;
}

.bg-grey{
	background: #ccc;
}

.zero {
	grid-column:span 2;
}

.left-cell{
	background: black;
}
.right-cell{
	display: grid;
	justify-items: center;
	align-items: end;
	background: black;
	font-size: 0.7rem;
	font-weight: lighter;
	color: darkgrey;
}
.side-text a:link{
	color:grey;
	text-decoration-style: dotted;
}

.calculator{
	background: #333333;
}

            
          
!
            
              /* TAKE AWAY :
*/
$(function() {
	/// TIME starts here --->>>>
	function loadTime() {
	url = "https://crossorigin.me/http://api.timezonedb.com/v2/get-time-zone?key=NVEQJECRKKG1&format=json&by=zone&zone=America/Los_Angeles";
		$.getJSON(url, function(json){
			$("#time").html(json.formatted);
			});
	}
	loadTime();
	console.log(json.formatted);

	/// CALCULATOR starts here --->>>>

	//array to hold all clicked values until result ( = ) is asked
	let arr = [];
	let operatorsArr = [];

	let resultStr = "";

	let term1 = 0;
	let term2 = 0;
	let result = 0;

	//prevent double click selecting text
	$("#1").mousedown(function(e){ e.preventDefault(); });
	//add values of all clicked cells to an array
	$("#1").click(function(){
		arr.push(1);
		term1 = Number(arr.join(""));
		if($("div#logNumber").html() == 0){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
		}
		if(($("div#logNumber").html()).length === 3){
			$("#logNumber").append(',');
		}
		if(($("div#logNumber").html()).length >= 7){
			$("#logNumber").append();
		}
		if(($("div#logNumber").html()).length < 7){
			$("#logNumber").append(1);
			}
		console.log(term1);
	});

	$("#2").mousedown(function(e){ e.preventDefault(); });
	$("#2").click(function(){
		arr.push(2);
		term1 = Number(arr.join(""));
		if($("div#logNumber").html() == 0){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
		}
		if(($("div#logNumber").html()).length === 3){
			$("#logNumber").append(',');
		}
		if(($("div#logNumber").html()).length < 7){
			$("#logNumber").append(2);
			}
		console.log(term1);
	});

	$("#3").mousedown(function(e){ e.preventDefault(); });
	$("#3").click(function(){
		arr.push(3);
		term1 = Number(arr.join(""));
		if($("div#logNumber").html() == 0){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
		}
		if(($("div#logNumber").html()).length === 3){
			$("#logNumber").append(',');
		}
		if(($("div#logNumber").html()).length < 7){
			$("#logNumber").append(3);
			}
		console.log(term1);
	});

	$("#4").mousedown(function(e){ e.preventDefault(); });
	$("#4").click(function(){
		arr.push(4);
		term1 = Number(arr.join(""));
		if($("div#logNumber").html() == 0){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
			}
		if(($("div#logNumber").html()).length === 3){
			$("#logNumber").append(',');
			}
		if(($("div#logNumber").html()).length < 7){
			$("#logNumber").append(4);
			}
		console.log(term1);
	});

	$("#5").mousedown(function(e){ e.preventDefault(); });
	$("#5").click(function(){
		arr.push(5);
		term1 = Number(arr.join(""));
		if($("div#logNumber").html() == 0){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
			}
		if(($("div#logNumber").html()).length === 3){
			$("#logNumber").append(',');
			}
		if(($("div#logNumber").html()).length < 7){
			$("#logNumber").append(5);
			}
		console.log(term1);
	});

	$("#6").mousedown(function(e){ e.preventDefault(); });
	$("#6").click(function(){
		arr.push(6);
		term1 = Number(arr.join(""));
		if($("div#logNumber").html() == 0){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
			}
		if(($("div#logNumber").html()).length === 3){
			$("#logNumber").append(',');
			}
		if(($("div#logNumber").html()).length < 7){
			$("#logNumber").append(6);
			}
		console.log(term1);
	});

	//>> TEST FOR DIGIT 7, THEN COPY TO OTHER DIGITS <<//
	$("#7").mousedown(function(e){ e.preventDefault(); });
	$("#7").click(function(){
		//append to HTML
		if($("div#logNumber").html() == 0){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
			}
		if(($("div#logNumber").html()) === "+"){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
			}
		if(($("div#logNumber").html()) === "-"){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
			}
		if(($("div#logNumber").html()) === "x"){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
			}
		if(($("div#logNumber").html()) === "/"){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
			}
		// insert thousand separator
		if(($("div#logNumber").html()).length === 3){
			$("#logNumber").append(',');
			}
		if(($("div#logNumber").html()).length === 7){
			$("#logNumber").append(',');
			}
		if(($("div#logNumber").html()).length === 11){
			$("#logNumber").append(',');
			}
		if(($("div#logNumber").html()).length === 15){
			$("#logNumber").append(',');
			}
		/*
		** TOT HIER : ADD RESPONSIVE RESULT FONT SIZE TO 0-9
		**
		*/
		// make font size responsive to input length
		if(($("div#logNumber").html()).length < 10){
			$("#logNumber").append(7);
		}
		if(($("div#logNumber").html()).length >= 10){
			$("#logNumber").css("font-size", "2.5rem");
			$("#logNumber").append(7);
		}
		if(($("div#logNumber").html()).length >= 15){
			$("#logNumber").css("font-size", "1.5rem");
			$("#logNumber").append(7);
		}

		//add to calculation
		arr.push(7);
		if(operatorsArr.indexOf('+') !== -1){
			term2 = Number(arr.join(""));
		}
		if(operatorsArr.indexOf('-') !== -1){
			term2 = Number(arr.join(""));
		}
		if(operatorsArr.indexOf('*') !== -1){
			term2 = Number(arr.join(""));
		}
		if(operatorsArr.indexOf('/') !== -1){
			term2 = Number(arr.join(""));
		}
		else{
			term1 = Number(arr.join(""));
		}
		console.log(term1, term2);

	});

	$("#8").mousedown(function(e){ e.preventDefault(); });
	$("#8").click(function(){
		//append to HTML
		if($("div#logNumber").html() == 0){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
			}
		if(($("div#logNumber").html()) === "+"){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
			}
		if(($("div#logNumber").html()) === "-"){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
			}
		if(($("div#logNumber").html()) === "x"){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
			}
		if(($("div#logNumber").html()) === "/"){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
			}
		if(($("div#logNumber").html()).length === 3){
			$("#logNumber").append(',');
			}
		if(($("div#logNumber").html()).length < 7){
			$("#logNumber").append(8);
		}

		//add to calculation
		arr.push(8);
		if(operatorsArr.indexOf('+') !== -1){
			term2 = Number(arr.join(""));
		}
		if(operatorsArr.indexOf('-') !== -1){
			term2 = Number(arr.join(""));
		}
		if(operatorsArr.indexOf('*') !== -1){
			term2 = Number(arr.join(""));
		}
		if(operatorsArr.indexOf('/') !== -1){
			term2 = Number(arr.join(""));
		}
		else{
			term1 = Number(arr.join(""));
		}
		console.log(term1, term2);
	});

	$("#9").mousedown(function(e){ e.preventDefault(); });
	$("#9").click(function(){
		//append to HTML
		if($("div#logNumber").html() == 0){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
			}
		if(($("div#logNumber").html()) === "+"){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
			}
		if(($("div#logNumber").html()) === "-"){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
			}
		if(($("div#logNumber").html()) === "x"){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
			}
		if(($("div#logNumber").html()) === "/"){
			$("div#logNumber").replaceWith("<div id='logNumber'></div>");
			}
		if(($("div#logNumber").html()).length === 3){
			$("#logNumber").append(',');
			}
		if(($("div#logNumber").html()).length < 7){
			$("#logNumber").append(9);
		}

		//add to calculation
		arr.push(9);
		if(operatorsArr.indexOf('+') !== -1){
			term2 = Number(arr.join(""));
		}
		if(operatorsArr.indexOf('-') !== -1){
			term2 = Number(arr.join(""));
		}
		if(operatorsArr.indexOf('*') !== -1){
			term2 = Number(arr.join(""));
		}
		if(operatorsArr.indexOf('/') !== -1){
			term2 = Number(arr.join(""));
		}
		else{
			term1 = Number(arr.join(""));
		}
		console.log(term1, term2);
	});

	$("#0").mousedown(function(e){ e.preventDefault(); });
	$("#0").click(function(){
		arr.push(0);
		term1 = Number(arr.join(""));
		$("#logNumber").append(0);
		console.log(term1);
	});

	$("#clear").mousedown(function(e){ e.preventDefault(); });
	$("#clear").click(function(){
		arr = [];
		operatorsArr = [];
		term1 = 0;
		term2 = 0;
	console.log(arr);
	$("div#logNumber").replaceWith("<div id='logNumber'>0</div>");
	});

	$("#plus").mousedown(function(e){ e.preventDefault(); });
	$("#plus").click(function(){
		operatorsArr.push('+');
		arr = [];
		$("div#logNumber").replaceWith("<div id='logNumber'>+</div>");
		console.log(operatorsArr, arr);
	});

	$("#minus").mousedown(function(e){ e.preventDefault(); });
	$("#minus").click(function(){
		operatorsArr.push('-');
		arr = [];
		$("div#logNumber").replaceWith("<div id='logNumber'>-</div>");
		console.log(operatorsArr, arr);
	});

	$("#multiply").mousedown(function(e){ e.preventDefault(); });
	$("#multiply").click(function(){
		operatorsArr.push('*');
		arr = [];
		$("div#logNumber").replaceWith("<div id='logNumber'>x</div>");
		console.log(operatorsArr, arr);
	});

	$("#divide").mousedown(function(e){ e.preventDefault(); });
	$("#divide").click(function(){
		operatorsArr.push('/');
		arr = [];
		$("div#logNumber").replaceWith("<div id='logNumber'>/</div>");
		console.log(operatorsArr, arr);
	});

	$("#result").mousedown(function(e){ e.preventDefault(); });
	// for chained calculation set operator hierarchy * / + -
		// using switch statement
	$("#result").click(function(){
		let operator = operatorsArr[0];
		switch (operator) {
			case '+':
				result = (term1 + term2);
				resultStr = result.toString();
				//insert thousand separator with RegEx
				result = resultStr.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
				$("div#logNumber").replaceWith("<div id='logNumber'>" + result + "</div>");
				operatorsArr = [];
				break;

				case '-':
					result = (term1 - term2);
					resultStr = result.toString();
					result = resultStr.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
					$("div#logNumber").replaceWith("<div id='logNumber'>" + result + "</div>");
					operatorsArr = [];
				break;

				case '*':
					result = (term1 * term2);
					resultStr = result.toString();
					result = resultStr.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
					$("div#logNumber").replaceWith("<div id='logNumber'>" + result + "</div>");
					operatorsArr = [];
				break;

				case '/':
					result = (term1 / term2);
					resultStr = result.toString();
					result = resultStr.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
					$("div#logNumber").replaceWith("<div id='logNumber'>" + result + "</div>");
					operatorsArr = [];
				break;

			default:
			$("div#logNumber").replaceWith("<div id='logNumber'>" + term1 + "</div>");
		}
		console.log(result, resultStr);
	});

});

            
          
!
999px

Console