Pen Settings



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


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


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.


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.


                <h1>Simple Calculator</h1>

<!-- Table to show calculator -->

  <!-- row to have result display and clear result  -->
    <td colspan="3">
      <input type="text" id="result" />

    <!-- clearResult() function will clear result textbox -->
      <input type="button" value="c" onclick="clearResult()" />

  <!-- numeric and operator button rows starts  -->
  <!-- create button and assign value to each button -->
    <!-- displayValue("1") will be called -->
    <td><input type="button" value="1" onclick="displayValue('1')" /> </td>
    <td><input type="button" value="2" onclick="displayValue('2')" /> </td>
    <td><input type="button" value="3" onclick="displayValue('3')" /> </td>
    <td><input type="button" value="/" onclick="displayValue('/')" /> </td>
    <td><input type="button" value="4" onclick="displayValue('4')" /> </td>
    <td><input type="button" value="5" onclick="displayValue('5')" /> </td>
    <td><input type="button" value="6" onclick="displayValue('6')" /> </td>
    <td><input type="button" value="-" onclick="displayValue('-')" /> </td>
    <td><input type="button" value="7" onclick="displayValue('7')" /> </td>
    <td><input type="button" value="8" onclick="displayValue('8')" /> </td>
    <td><input type="button" value="9" onclick="displayValue('9')" /> </td>
    <td><input type="button" value="+" onclick="displayValue('+')" /> </td>
  <!-- last row  -->
    <td><input type="button" value="." onclick="displayValue('.')" /> </td>
    <td><input type="button" value="0" onclick="displayValue('0')" /> </td>

    <!-- solve() will evaluate value and display to result -->
    <td><input type="button" value="=" onclick="solve()" /> </td>

    <td><input type="button" value="*" onclick="displayValue('*')" /> </td>
  <!-- numeric and operator button rows ends  -->


                /* Custom CSS */
h1 { text-align: center;}
table {
  margin: auto;
  border-collapse: collapse;
  border-radius: 5px;
  border: 1px solid #eee;
td, th {
  text-align: left;
  /* Uncomment below and see */
  /* background-color: #eee; */
  padding: 8px;
input[type="button"] {
  background-color: #eee;
  color: #111;
  width: 100%;
  border-radius: 5px;
  width: 60px;
  height: 40px;
  font-size: 20px;
  box-shadow: 0 5px rgba(0,0,0,0.2);
  margin: 10px;
  border: 1px solid #eee;
input[type="button"]:focus {
 outline: 0;
input[type="button"]:hover {
  background-color: #ccc;
input[type="text"] {
  background-color: white;
  width: 90%;
  border-radius: 5px;
  text-align: right;
  height: 40px;
  border: 1px solid #ccc;
  margin-left: 10px;
table tr:first-child {
  border-bottom: 1px solid #eee;



                const OPERATORS = ["+", "-", "*", "/"];
// display value
function displayValue(val) {
  let initialVal = document.getElementById("result").value;

  if (initialVal == "") {
    if (OPERATORS.indexOf(val) != -1) {
  document.getElementById("result").value += val;

// evaluates the digit and return result
function solve() {
  let x = document.getElementById("result").value;
  if (x == "") {
  let y = eval(x);
  document.getElementById("result").value = y;

// clear the result
function clearResult() {
  document.getElementById("result").value = "";