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 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

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.

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

              
                <html>
	<head>
		<title>Apple Calculator</title>
	</head>
	<body>
		<div class="wrapper">
		<div class="calc-body">
			<div class="readout">
				<span class="value" id="output">0</span>
			</div>
			<div id="button-panel" class="buttons">
				<div class="left-side">
					<button id="f-mp" class="small">m+</button>
					<button id="f-mm" class="small">m-</button>
					<button id="f-mc" class="small">mc</button>
					<button id="f-mr" class="small">mr</button>
					<button id="n-7" class="big">7</button>
					<button id="n-8" class="big">8</button>
					<button id="n-9" class="big">9</button>
					<button id="n-4" class="big">4</button>
					<button id="n-5" class="big">5</button>
					<button id="n-6" class="big">6</button>
					<button id="n-1" class="big">1</button>
					<button id="n-2" class="big">2</button>
					<button id="n-3" class="big">3</button>
					<button id="n-0" class="big">0</button>
					<button id="n-p" class="big">.</button>
					<button id="f-c" class="big">c</button>
				</div>
				<div class="right-side">
					<button id="f-d" class="small">&#247;</button>
					<button id="f-t" class="small">&#215;</button>
					<button id="f-m" class="small">&#45;</button>
					<button id="f-a" class="small">&#43;</button>
					<button id="f-e" class="small tall">&#61;</button>
				</div>
			</div>
		</div>
	</div>
 </html>
              
            
!

CSS

              
                /* Welcome to Compass.
 * In this file you should write your main styles. (or centralize your imports)
 * Import this file using the following HTML or equivalent:
 * <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css" /> */
/* line 17, ../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
  font: inherit;
  font-size: 100%;
  vertical-align: baseline;
}

/* line 22, ../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */
html {
  line-height: 1;
}

/* line 24, ../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */
ol, ul {
  list-style: none;
}

/* line 26, ../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */
table {
  border-collapse: collapse;
  border-spacing: 0;
}

/* line 28, ../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */
caption, th, td {
  text-align: left;
  font-weight: normal;
  vertical-align: middle;
}

/* line 30, ../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */
q, blockquote {
  quotes: none;
}
/* line 103, ../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */
q:before, q:after, blockquote:before, blockquote:after {
  content: "";
  content: none;
}

/* line 32, ../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */
a img {
  border: none;
}

/* line 116, ../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section, summary {
  display: block;
}

/* line 9, ../sass/screen.scss */
body {
  background-color: #545454;
  background-size: 13px 13px, 13px 13px;
  background-position: -2px -2px, -2px -2px;
  background-image: -moz-linear-gradient(#474747 1px, transparent 1px), -moz-linear-gradient(0, #474747 1px, transparent 1px);
  background-image: -webkit-linear-gradient(#474747 1px, transparent 1px), -webkit-linear-gradient(0, #474747 1px, transparent 1px);
  background-image: -ms-linear-gradient(#474747 1px, transparent 1px), -ms-linear-gradient(0, #474747 1px, transparent 1px);
}

/* line 17, ../sass/screen.scss */
div, button, span {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

/* line 21, ../sass/screen.scss */
.wrapper {
  width: 156px;
  height: 234px;
  position: relative;
  margin: 50px;
}
/* line 29, ../sass/screen.scss */
.wrapper .calc-body {
  width: 100%;
  height: 100%;
  padding: 6px;
  margin: 0;
  -webkit-border-radius: 10px;
  -moz-border-radius: 10px;
  -ms-border-radius: 10px;
  -o-border-radius: 10px;
  border-radius: 10px;
  -webkit-box-shadow: 0 3px 8px 0px rgba(0, 0, 0, 0.7);
  -moz-box-shadow: 0 3px 8px 0px rgba(0, 0, 0, 0.7);
  box-shadow: 0 3px 8px 0px rgba(0, 0, 0, 0.7);
  
  background-image: -webkit-linear-gradient(#fd823a, #fc6a27);
  background-image: -moz-linear-gradient(#fd823a, #fc6a27);
}
/* line 38, ../sass/screen.scss */
.wrapper .calc-body .readout {
  -webkit-box-shadow: inset 0 2px 3px 0px rgba(0, 0, 0, 0.3);
  -moz-box-shadow: inset 0 2px 3px 0px rgba(0, 0, 0, 0.3);
  box-shadow: inset 0 2px 3px 0px rgba(0, 0, 0, 0.3);
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  -ms-border-radius: 5px;
  -o-border-radius: 5px;
  border-radius: 5px;
  background-image: -webkit-linear-gradient(#b6dcf0, #b6dcf0 46%, #a2d3ee 46%, #acd8f0);
  background-image: -moz-linear-gradient(#b6dcf0, #b6dcf0 46%, #a2d3ee 46%, #acd8f0);
  width: 100%;
  height: 35px;
  margin-bottom: 6px;
  background-color: #a9d6f0;
}
/* line 47, ../sass/screen.scss */
.wrapper .calc-body .readout .value {
  font-family: Arial;
  color: #434343;
  padding: 10px;
  padding-top: 15px;
  display: block;
  width: 100%;
  height: 100%;
  text-align: right;
}
/* line 60, ../sass/screen.scss */
.wrapper .calc-body .buttons {
  width: 100%;
  height: 181px;
  background-image: -webkit-linear-gradient(#cacaca, #bbbbbb);
  background-image: -moz-linear-gradient(#cacaca, #bbbbbb);
  -webkit-box-shadow: inset 0 1px 1px 0px rgba(0, 0, 0, 0.3);
  -moz-box-shadow: inset 0 1px 1px 0px rgba(0, 0, 0, 0.3);
  box-shadow: inset 0 1px 1px 0px rgba(0, 0, 0, 0.3);
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  -ms-border-radius: 5px;
  -o-border-radius: 5px;
  border-radius: 5px;
}
/* line 68, ../sass/screen.scss */
.wrapper .calc-body .buttons .left-side {
  padding: 3px;
  width: 115px;
  float: left;
}
/* line 74, ../sass/screen.scss */
.wrapper .calc-body .buttons .right-side {
  padding: 3px;
  width: 29px;
  float: left;
}
/* line 79, ../sass/screen.scss */
.wrapper .calc-body .buttons .right-side button.small:not(:first-child) {
  margin-top: 6px;
}
/* line 85, ../sass/screen.scss */
.wrapper .calc-body .buttons button {
  -webkit-box-shadow: 0 1px 2px 0px rgba(0, 0, 0, 0.4);
  -moz-box-shadow: 0 1px 2px 0px rgba(0, 0, 0, 0.4);
  box-shadow: 0 1px 2px 0px rgba(0, 0, 0, 0.4);
  background-image: -webkit-linear-gradient(white, #e9e9e9);
  outline: none;
  text-align: center;
  border: 2px solid #fff;
  display: inline-block;
  font-family: Arial;
  font-weight: bold;
  color: #868686;
  -webkit-border-radius: 50% 50%;
  -moz-border-radius: 50% / 50%;
  border-radius: 50% / 50%;
}
/* line 98, ../sass/screen.scss */
.wrapper .calc-body .buttons button:active {
  background-image: -webkit-linear-gradient(#e9e9e9, white);
}
/* line 102, ../sass/screen.scss */
.wrapper .calc-body .buttons button.active {
  background-image: -webkit-linear-gradient(#fdb474, #fd9030);
  background-image: -moz-linear-gradient(#fdb474, #fd9030);
  color: white;
}
/* line 107, ../sass/screen.scss */
.wrapper .calc-body .buttons button.small {
  margin: 1px;
  width: 22px;
  height: 22px;
  font-size: 8px;
  padding: 0;
}
/* line 116, ../sass/screen.scss */
.wrapper .calc-body .buttons button.tall {
  height: 54px;
  -webkit-border-radius: 11px 11px;
  -moz-border-radius: 11px / 11px;
  border-radius: 11px / 11px;
}
/* line 121, ../sass/screen.scss */
.wrapper .calc-body .buttons button.big {
  width: 33px;
  height: 33px;
  margin-top: 4px;
  border: 3px solid #fff;
}
              
            
!

JS

              
                (function(){

			var display = document.getElementById("output");
			
			var operatorFn = null;
			var RegA = 0;
			var RegB = 0;
			var resultMode = false;
			var screenText = "";
			var screenIsDecimal = false;
			var activeButton = null;

			var bp = document.getElementById("button-panel");
			bp.addEventListener("click", function(event){
				var target = event.target;
				if(target.tagName === "BUTTON"){
					
					var fn = target.getAttribute("id").split("-");

					if(fn[0] === "n"){
						number(fn[1]);
					} else {
						switch(fn[1]){
							case "c":
								reset(true);
							break;
							case "t":
							case "m":
							case "a":
							case "d":
								operate(fn[1], target);
							break;
							case "e":
								equals();
							break;
						}
					}


				}
			}, true);

			function buttonShowActive(button){

				// First deactivate any other button
				buttonsShowInactive();

				activeButton = button;
				addClass(button, "active");
			}

			function buttonsShowInactive(){
				if(activeButton){
					removeClass(activeButton, "active");
					activeButton = null;
				}
			}

			/**
			 * Adds a class to the given object
			 * @param {[type]} object [description]
			 * @param {[type]} cls    [description]
			 */
			function addClass(object, cls){
				object.className += " " + cls;
			}

			function removeClass(object, cls){
				object.className = object.className.replace(cls, "").replace(/\s+/g, ' ').trim();
			}

			function operate(method, button){
				console.log("operate");

				buttonShowActive(button);

				operatorFn = method;

				if(resultMode){
					console.log("Result mode");
					RegB = 0;
					dumpReg();
					resultMode = false;
				} else {
					if(!RegA){
						RegA = +screenText;
					} else  {
						RegB = +screenText;
						calculate();
					}
				}

				// Clear out the input
				screenText = "";
			}

			function output(value){
         value = "" + value;
				display.innerHTML = value.substring(0, 14);
			}

			function reset(zero){
				resultMode = false;
				screenIsDecimal = false;
				RegA = 0;
				RegB = 0;
				if (zero)
					screenText = "0";
				else
					screenText = "";
				operatorFn = null;
				buttonsShowInactive();
				output(screenText);
			}

			function number(n){

				if(resultMode){
					reset();
					console.log("resuilts");
				}

				buttonsShowInactive();

				if(n === "p"){
					if(!screenIsDecimal){
						screenIsDecimal = true;
						output(screenText += ".");
					}
				} else {
					if(+n != 0 && +screenText == 0 && screenText != ".")
						screenText = "";
					if(+n == 0 && +screenText == 0)
						screenText = "0";
					else
						screenText += n;
					output(screenText);
				}
			}

			function equals(){
				resultMode = true;
				RegB = +screenText;
				calculate();
			}

			function dumpReg(){
				console.log("RegA "+RegA);
				console.log("RegB "+RegB);
			}

			function calculate(){
				console.log("Calculating...");
				dumpReg();

				switch(operatorFn){
					case "t":
						RegA = RegA * RegB;
					break;
					case "m":
						RegA = RegA - RegB;
					break;
					case "d":
						RegA = RegA / RegB;
					break;
					case "a":
						RegA = RegA + RegB;
					break;
					// do nothing if we have no operator
					default:
					return;
					break;
				}
				dumpReg();
				output(RegA);
			}

		})();
              
            
!
999px

Console