Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm 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. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

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="main">
  <div class="top">
    
    <div class="top2">
      <a class="mainlogo">XASIO</a>
      <a class="logo">fg-81RS PLUS</a>
      <a class="logo2">natural vcm</a>
    </div>
    
    <div class="top1">
      <div class = "solar">
        <div class="line"></div>
        <div class="line"></div>
        <div class="line"></div>
      </div>
    </div>
    
  </div>
  <textarea rows="4" cols="22" class="screen">
  </textarea>
  
  <div class="controls">
    <div class="button-placeholder">
      <a class="button">7</a>
      <a class="button">4</a>
      <a class="button">1</a>
      <a class="button">0</a>
    </div>

    <div class = "button-placeholder">
      <a class="button">8</a>
      <a class="button">5</a>
      <a class="button">2</a>
      <a class="button">.</a>
    </div>

    <div class = "button-placeholder">
      <a class="button">9</a>
      <a class="button">6</a>
      <a class="button">3</a>
      <a class="operation"></a>
    </div>

    <div class = "button-placeholder">
     <a class="operation" id="division">/</a>
      <a class="operation" id="multiply">x</a>
      <a class="operation" id="plus">+</a>
      <a class="operation" id="minus">-</a>      
    </div>

    <div class = "button-placeholder">
      <a class="operation" id="ac">ac</a>
      <a class="operation"></a>
      <a class="operation"></a>
      <a class="operation" id="equals">=</a>
    </div>
  </div>
</div>
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=VT323');
@import url('https://fonts.googleapis.com/css?family=Orbitron');

.main {
  width: 250px;
  height: 380px;
  border-radius: 30px;
  border: 3px solid #b2b2b2;
  box-shadow: 0px 0px 25px 0px black;
  background-color:#494949;
  display:flex;
  flex-direction:column;
  position: absolute;
}

.top {
  align-self:center;
  display: flex;
  width:100%;
}

.top1 {
  flex:1.5;
}

.top2 {
  display:flex;
  flex:1;
  flex-direction:column;
  justify-content:flex-end;
  align-items:flex-start;
}

.mainlogo {
  margin-left:30px;
  color:white;
  margin-bottom:4px;
  font-size:14px;
}

.logo {
  color:white;
  font-size:8px;
  margin-left:30px;
}

.logo2 {
  color:#a35e72;
  font-size:8px;
  margin-left:30px;
}

.solar {
  width:120px;
  height:40px;
  background-color:#4e332c;
  border-radius:10px;
  box-shadow: inset 0px 0px 8px 0px #333333;
  margin-top:15px;
  display:flex;
  margin-left:5px;
}

.line {
  border:1px solid #1c1c1c;
  border-top:none;
  border-bottom:none;
  width:35%;
  height:40px;
}

.line:nth-child(1) {
  border-left:none;
}

.line:nth-child(3) {
  border-right:none;
}

.screen {
  width:200px;
  height:100px;
  background-color:#d4e2e1;
  border-radius:10px;
  align-self: center;
  margin-top:10px;
  box-shadow: inset 0px 0px 7px 0px #595959;
  box-sizing:border-box;
  padding:10px;
  font-size:28px;
  font-family: 'VT323', monospace;
}

.controls {
  display:flex;
  flex-direction:row;
  margin-top:30px;
  margin-left:auto;
  margin-right:auto;
  width:85%;
}

.button-placeholder {
  display:flex;
  flex-direction:column;
  width:20%;
}

.button, .operation {
  user-select:none;
  width:90%;
  height:20px;
  margin-bottom:5px;
  padding-top:4px;
  padding-bottom:4px;
  background-color:#333333;
  color:white;
  /*border-top: 2px solid #7c7c7c;
  border-left:1px solid grey;
  border-right:1px solid grey;*/
  box-shadow: 0px 3px #7c7c7c;
  text-align:center;
  border-radius:10px;
  cursor:default;
  font-family: 'Orbitron', sans-serif;
  font-size:14px;
}

.button:active, .operation:active {
  box-shadow: 0px 1px #878787;
  transform: translateY(2px);
  cursor:default;
}
            
          
!
            
              let result;
let operation = [];//allready present as param
let index = 0;
let numberIndex = 0; //not needed
let operationArr;
let numberArr;
let subArr;
let operationIndex;

function divide() {
  if (operation.indexOf("/") > -1) {
    while (operation.indexOf("/") !== -1) {
      operationIndex = operation.indexOf("/");
      subArr = operation.slice(operationIndex - 1, operationIndex + 2);
      operationArr = subArr.filter(element => element === "+" || element === "-" || element === "/" || element === "*");
      numberArr = subArr.filter(element => element !== "+" && element !== "-" && element !== "*" && element !== "/");
      acc2 = numberArr.reduce(parser);
      operation.splice(operationIndex - 1, 3, acc2);
      index = 0;
    }
  }

}

function multiply() {
  if (operation.indexOf("*") > -1) {
    while (operation.indexOf("*") !== -1) {
      operationIndex = operation.indexOf("*");
      console.log("executor entered for * at index: ", operationIndex);
      subArr = operation.slice(operationIndex - 1, operationIndex + 2);
      operationArr = subArr.filter(element => element === "+" || element === "-" || element === "/" || element === "*");
      numberArr = subArr.filter(element => element !== "+" && element !== "-" && element !== "*" && element !== "/");
      acc2 = numberArr.reduce(parser);
      operation.splice(operationIndex - 1, 3, acc2);
      index = 0;
      console.log("acc2: ", acc2);
      console.log("subArr: " + subArr);
      console.log("numberArr: " + numberArr);
      console.log("operationArr: " + operationArr);
      console.log("operation: " + operation);
    }
  }
}

function add() {
  if (operation.indexOf("+") > -1) {
    while (operation.indexOf("+") !== -1) {
      operationIndex = operation.indexOf("+");
      console.log("executor entered for + at index: ", operationIndex);
      subArr = operation.slice(operationIndex - 1, operationIndex + 2);
      operationArr = subArr.filter(element => element === "+" || element === "-" || element === "/" || element === "*");
      numberArr = subArr.filter(element => element !== "+" && element !== "-" && element !== "*" && element !== "/");
      acc2 = numberArr.reduce(parser);
      operation.splice(operationIndex - 1, 3, acc2);
      index = 0;
      console.log("acc2: ", acc2);
      console.log("subArr: " + subArr);
      console.log("numberArr: " + numberArr);
      console.log("operationArr: " + operationArr);
      console.log("operation: " + operation);
    }
  }
}

function subtract() {
  if (operation.indexOf("-") > -1) {
    while (operation.indexOf("-") !== -1) {
      operationIndex = operation.indexOf("-");
      console.log("executor entered for - at index: ", operationIndex);
      subArr = operation.slice(operationIndex - 1, operationIndex + 2);
      operationArr = subArr.filter(element => element === "+" || element === "-" || element === "/" || element === "*");
      numberArr = subArr.filter(element => element !== "+" && element !== "-" && element !== "*" && element !== "/");
      acc2 = numberArr.reduce(parser);
      operation.splice(operationIndex - 1, 3, acc2);
      index = 0;
      console.log("acc2: ", acc2);
      console.log("subArr: " + subArr);
      console.log("numberArr: " + numberArr);
      console.log("operationArr: " + operationArr);
      console.log("operation: " + operation);
    }
  }
}

function parser(acc, element) {
  console.log("accumalator: ", acc, " element: ", element, " operation: ", operationArr[index], " index: ", index);
  if (operationArr[index] === "/") {
    acc = parseFloat(acc) / parseFloat(element);
    index++;
    return acc;
  }
  if (operationArr[index] === "*") {
    acc = parseFloat(acc) * parseFloat(element);
    index++;
    return acc;
  }
  if (operationArr[index] === "+") {
    acc = parseFloat(acc) + parseFloat(element);
    index++;
    return acc;
  }
  if (operationArr[index] === "-") {
    acc = parseFloat(acc) - parseFloat(element);
    index++;
    return acc;
  }
}

$(".button").on("click", function() {
  if ($(this).text() === ".") {
    if (operation[numberIndex][operation[numberIndex].length - 1] === "." || operation[numberIndex].indexOf(".") > -1) {
      return;
    }

  }
  if (operation[numberIndex] === undefined) {
    operation.push("");
  }
  operation[numberIndex] += $(this).text();
  console.log(operation);
  $(".screen").html(operation);
});
// ADDITION OPERATOR

$("#plus").on("click", function() {
  if (operation.length !== 0) {
    if (operation[operation.length - 1] !== "+" && operation[operation.length - 1] !== "-" && operation[operation.length - 1] !== "*" && operation[operation.length - 1] !== "/") {
      numberIndex += 2;
      operation.push("+");
      console.log(operation);
      $(".screen").html(operation);
    }
  }

});

// MINUS OPERATOR

$("#minus").on("click", function() {
  if (operation.length !== 0) {
    if (operation[operation.length - 1] !== "+" && operation[operation.length - 1] !== "-" && operation[operation.length - 1] !== "*" && operation[operation.length - 1] !== "/") {
      numberIndex += 2;
      operation.push("-");
      console.log(operation);
      $(".screen").html(operation);
    }
  }
});

// MULTIPLICATION OPERATOR

$("#multiply").on("click", function() {
  if (operation.length != 0) {
    if (operation[operation.length - 1] !== "+" && operation[operation.length - 1] !== "-" && operation[operation.length - 1] !== "*" && operation[operation.length - 1] !== "/") {
      numberIndex += 2;
      operation.push("*");
      console.log(operation);
      $(".screen").html(operation);
    }
  }
});

// DIVISION OPERATOR 

$("#division").on("click", function() {
  if (operation.length != 0) {
    if (operation[operation.length - 1] !== "+" && operation[operation.length - 1] !== "-" && operation[operation.length - 1] !== "*" && operation[operation.length - 1] !== "/") {
      numberIndex += 2;
      operation.push("/");
      console.log(operation);
      $(".screen").html(operation);
    }
  }
});

// EQUAL OPERATOR

$("#equals").on("click", function() {
  divide();
  multiply();
  add();
  subtract();
  result = operation;
  console.log("result:", result);
  $(".screen").html(result);
  operation = [];
  operation[0] = result[0];
  index = 0;
  numberIndex = 0;
});

// HELPER OPERATORS

$("#ac").on("click", function() {
  operation = [];
  index = 0;
  numberIndex = 0;
  $(".screen").html("");
  console.log("cleared operation:", operation);
});

$(document).keydown(function(e) {
  switch (e.which) {
    case 96:
    case 48:
      {
        if (operation[numberIndex] === undefined) {
          operation.push("");
        }
        operation[numberIndex] += "0";
        console.log(operation);
        $(".screen").html(operation);
      }
      break;

    case 97:
    case 49:
      {
        if (operation[numberIndex] === undefined) {
          operation.push("");
        }
        operation[numberIndex] += "1";
        console.log(operation);
        $(".screen").html(operation);
      }
      break;

    case 98:
    case 50:
      {
        if (operation[numberIndex] === undefined) {
          operation.push("");
        }
        operation[numberIndex] += "2";
        console.log(operation);
        $(".screen").html(operation);
      }
      break;

    case 99:
    case 51:
      {
        if (operation[numberIndex] === undefined) {
          operation.push("");
        }
        operation[numberIndex] += "3";
        console.log(operation);
        $(".screen").html(operation);
      }
      break;
    case 100:
    case 52:
      {
        if (operation[numberIndex] === undefined) {
          operation.push("");
        }
        operation[numberIndex] += "4";
        console.log(operation);
        $(".screen").html(operation);
      }
      break;
    case 101:
    case 53:
      {
        if (operation[numberIndex] === undefined) {
          operation.push("");
        }
        operation[numberIndex] += "5";
        console.log(operation);
        $(".screen").html(operation);
      }
      break;
    case 102:
    case 54:
      {
        if (operation[numberIndex] === undefined) {
          operation.push("");
        }
        operation[numberIndex] += "6";
        console.log(operation);
        $(".screen").html(operation);
      }
      break;
    case 103:
    case 55:
      {
        if (operation[numberIndex] === undefined) {
          operation.push("");
        }
        operation[numberIndex] += "7";
        console.log(operation);
        $(".screen").html(operation);
      }
      break;
    case 104:
    case 56:
      {
        if (operation[numberIndex] === undefined) {
          operation.push("");
        }
        operation[numberIndex] += "8";
        console.log(operation);
        $(".screen").html(operation);
      }
      break;
    case 105:
    case 57:
      {
        if (operation[numberIndex] === undefined) {
          operation.push("");
        }
        operation[numberIndex] += "9";
        console.log(operation);
        $(".screen").html(operation);
      }
      break;
    case 187:
    case 13:
      {
        divide();
        multiply();
        add();
        subtract();
        result = operation;
        console.log("result:", result);
        $(".screen").html(result);
        operation = [];
        operation[0] = result;
        index = 0;
        numberIndex = 0;
      }
      break;
    case 107:
      {
        if (operation.length !== 0) {
          if (operation[operation.length - 1] !== "+" && operation[operation.length - 1] !== "-" && operation[operation.length - 1] !== "*" && operation[operation.length - 1] !== "/") {
            numberIndex += 2;
            operation.push("+");
            console.log(operation);
            $(".screen").html(operation);
          }
        }

      }
      break;
    case 109:
      {
        if (operation.length != 0) {
          if (operation[operation.length - 1] !== "+" && operation[operation.length - 1] !== "-" && operation[operation.length - 1] !== "*" && operation[operation.length - 1] !== "/") {
            numberIndex += 2;
            operation.push("-");
            console.log(operation);
            $(".screen").html(operation);
          }
        }

      }
      break;
    case 106:
      {
        if (operation.length != 0) {
          if (operation[operation.length - 1] !== "+" && operation[operation.length - 1] !== "-" && operation[operation.length - 1] !== "*" && operation[operation.length - 1] !== "/") {
            numberIndex += 2;
            operation.push("*");
            console.log(operation);
            $(".screen").html(operation);
          }
        }

      }
      break;
    case 111:
      {
        if (operation.length != 0) {
          if (operation[operation.length - 1] !== "+" && operation[operation.length - 1] !== "-" && operation[operation.length - 1] !== "*" && operation[operation.length - 1] !== "/") {
            numberIndex += 2;
            operation.push("/");
            console.log(operation);
            $(".screen").html(operation);
          }
        }

      }
      break;
    case 8:
    case 46:
      {
        operation = [];
        index = 0;
        numberIndex = 0;
        $(".screen").html("");
        console.log("cleared operation:", operation);
      }
      break;
    case 110:
    case 190:
      {
        if (operation[numberIndex][operation[numberIndex].length - 1] === "." || operation[numberIndex].indexOf(".") > -1) {
          return;
        }
        if (operation[numberIndex] === undefined) {
          operation.push("");
        }
        operation[numberIndex] += ".";
        console.log(operation);
        $(".screen").html(operation);
      }
    default:
      return; // exit this handler for other keys
  }
  e.preventDefault(); // prevent the default action (scroll / move caret)
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console