JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
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.
<!-- <div class="container-fixed"> -->
<div class="container">
<div class="calculator">
<div class="row">
<div class="col-xs-4 col-md-offset-4 text-center" id="title">
REVERSE POLISH NOTATION CALCULATOR
</div>
</div>
<div class="row">
<div class="col-xs-4 col-md-offset-4 text-center" id="rtfm">
<span id="rtfm" data-toggle="modal" data-target="#help">
RTFM here
</span>
<!-- Modal -->
<div id="help" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">How to use an RPN calculator?</h4>
</div>
<div class="modal-body text-left">
<p>A reverse Polish notation calculator works like this:</p>
<ol>
<li>Type a number... any number.</li>
<li>Press ENT</li>
<li>Repeat steps 1 and 2</li>
<li>Press an operation button (+-*/)</li>
</ol>
<p>Every time the you enter a number followed by ENT, you push a number in the stack. When the stack has two or more numbers the operation buttons become active. When you press an operation button, the calculator pops the two most recent numbers out of the stack, performs the selected operation and pushes the result in the stack.</p>
<p>An RPN calculator is a fast, elegant and super cool way to perform calculations with fewer keystrokes than with an algebraic calculator.</p>
<p>Read more about <a href="https://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">RPN on Wikipedia!</a></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- display stack -->
<div class="row">
<div id="div-stack" class="col-xs-4 col-md-offset-4 div-display"></div>
</div>
<!-- /display stack -->
<!-- display -->
<div class="row">
<div id="div-display" class="col-xs-4 col-md-offset-4 div-display"></div>
</div>
<!-- /display -->
<!-- first row of keys -->
<div class="row">
<div class="col-xs-4 col-md-offset-4 div-button-row">
<div class="col-xs-3 calc-button calc-button-left">CE</div>
<div class="col-xs-3 calc-button">C</div>
<div class="col-xs-3 calc-button" id="button-smiley">:)</div>
<div class="col-xs-3 calc-button operation-button">/</div>
</div>
</div>
<!-- /first row of keys -->
<!-- second row of keys -->
<div class="row">
<div class="col-xs-4 col-md-offset-4 div-button-row">
<div class="col-xs-3 calc-button calc-button-left">7</div>
<div class="col-xs-3 calc-button">8</div>
<div class="col-xs-3 calc-button">9</div>
<div class="col-xs-3 calc-button operation-button">*</div>
</div>
</div>
<!-- /second row of keys -->
<!-- third row of keys -->
<div class="row">
<div class="col-xs-4 col-md-offset-4 div-button-row">
<div class="col-xs-3 calc-button calc-button-left">4</div>
<div class="col-xs-3 calc-button">5</div>
<div class="col-xs-3 calc-button">6</div>
<div class="col-xs-3 calc-button operation-button">-</div>
</div>
</div>
<!-- /third row of keys -->
<!-- fourth row of keys -->
<div class="row">
<div class="col-xs-4 col-md-offset-4 div-button-row">
<div class="col-xs-3 calc-button calc-button-left">1</div>
<div class="col-xs-3 calc-button">2</div>
<div class="col-xs-3 calc-button">3</div>
<div class="col-xs-3 calc-button operation-button">+</div>
</div>
</div>
<!-- /fourth row of keys -->
<!-- fifth row of keys -->
<div class="row">
<div class="col-xs-4 col-md-offset-4 div-button-row">
<div class="col-xs-6 calc-button calc-button-left">0</div>
<div class="col-xs-3 calc-button">.</div>
<div class="col-xs-3 calc-button">ENT</div>
</div>
</div>
<!-- /fifth row of keys -->
</div>
<!-- </div> -->
@import url(https://fonts.googleapis.com/css?family=Montserrat);
@font-face {
font-family: "digital-7";
src: url(https://dl.dropboxusercontent.com/u/393119/web/digital-7%20%28mono%29.ttf) format("truetype");
}
$brokenwhite: #ddd;
$border: #c0c0c9;
$button: #333;
$background: #057;
$display: #beb;
$calc-width: 390px;
body {
background-color: $background;
}
#title {
font-family: montserrat;
font-size: 1.5em;
color: $brokenwhite;
}
.calculator {
margin-top: 80px;
}
.div-display {
width: $calc-width !important;
font-family: "digital-7";
font-size: 3em;
text-align: right;
color: $button;
background-color: $display;
height: 1.5em;
padding-right: .75em;
border-left: solid;
border-right: solid;
border-color: $border;
}
#div-display {
border-bottom: solid;
border-color: $border;
}
#div-stack {
border-top: solid;
border-color: $border;
text-align: left;
}
.div-button-row {
width: $calc-width !important;
font-family: "verdana";
font-size: 2em;
text-align: center;
background-color: $button;
padding: 0px;
}
.calc-button {
color: white;
border-right: solid;
border-bottom: solid;
// color: $display;
border-color: $border;
height: 1.5em;
}
.calc-button:hover {
cursor: pointer;
}
.calc-button-left {
border-right: solid;
border-left: solid;
border-color: $border
}
.calc-button-pressed {
background-color: blue;
}
.calc-button-inactive {
color: gray;
}
.tissit {
text-align:center;
font-size:.9em;
height: 1.65em;
}
#rtfm {
color: gray;
}
#rtfm:hover {
cursor: pointer;
}
$(document).ready(function() {
var stack = [];
var operationDone = false;
var lastButtonPressed = null;
$(".operation-button").addClass("calc-button-inactive");
clearDisplay();
$(".calc-button").click(function(event) {
if (lastButtonPressed) {
lastButtonPressed.removeClass("calc-button-pressed");
}
var btnPressed = $(this).html();
if (btnPressed === "C") {
lastButtonPressed = $(this).addClass("calc-button-pressed");
clearDisplay();
clearStackDisplay();
stack = [];
} else if (btnPressed === "CE") {
lastButtonPressed = $(this).addClass("calc-button-pressed");
clearDisplay();
} else if ("+-*/".indexOf(btnPressed) !== -1 && stack.length > 1) {
//console.log(stack.length);
lastButtonPressed = $(this).addClass("calc-button-pressed");
if (btnPressed === "+") {
stack = sum(stack);
operationDone = true;
} else if (btnPressed === "-") {
stack = sub(stack);
operationDone = true;
} else if (btnPressed === "*") {
stack = multiply(stack);
operationDone = true;
} else if (btnPressed === "/") {
stack = divide(stack);
operationDone = true;
}
} else if (btnPressed === "ENT") {
lastButtonPressed = $(this).addClass("calc-button-pressed");
stack.push(parseFloat(getDisplay()));
setDisplayStack(stack);
clearDisplay();
} else if ("0123456789.".indexOf(btnPressed) !== -1) {
lastButtonPressed = $(this).addClass("calc-button-pressed");
if (operationDone) {
clearDisplay();
operationDone = false;
}
if (btnPressed === "." && getDisplay().indexOf(".") === -1 || btnPressed !== ".") {
addToDisplay($(this).html());
}
}
if (stack.length < 2) {
$(".operation-button").addClass("calc-button-inactive");
} else {
$(".operation-button").removeClass("calc-button-inactive");
}
});
})
function addToDisplay(d) {
var oldValue = getDisplay();
if (oldValue === "0") {
$("#div-display").html("");
oldValue = "";
}
if (oldValue.length < 18) {
var newValue = oldValue + d;
setDisplay(newValue);
if (newValue === "715517") {
tissit();
}
}
}
function setDisplay(s) {
$("#div-display").html(s);
}
function setDisplayStack(s) {
$("#div-stack").html(s.join(" "));
}
function getDisplay() {
return $("#div-display").html();
}
function clearDisplay() {
$("#div-display").html("0");
}
function clearStackDisplay() {
$("#div-stack").html("");
}
function sum(stack) {
stack.push(stack.pop() + stack.pop());
clearDisplay();
setDisplayStack(stack);
return stack;
}
function sub(stack) {
var last = stack.pop();
stack.push(stack.pop() - last);
clearDisplay();
setDisplayStack(stack);
return stack;
}
function multiply(stack) {
stack.push(stack.pop() * stack.pop());
clearDisplay();
setDisplayStack(stack);
return stack;
}
function divide(stack) {
var last = stack.pop();
stack.push(stack.pop() / last);
clearDisplay();
setDisplayStack(stack);
return stack;
}
function tissit() {
$("#button-smiley").addClass("tissit");
$("#button-smiley").html("(.)(.)");
}
Also see: Tab Triggers