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

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

              
                <body>
  <div class="container">
    <select onChange="onSelect(this)" class="topRightCorner" >
  <option value="0">English</option>
  <option value="1">中文(Chinese)</option>
</select>
    <div class="boxLeft">
      <h2 id = '0' class="boxLeftH2">Information</h2>
      <div id='1' >Input two positive integer numbers and get the result of multiplication of those two numbers.</div>
      <br />
      <div id='2'>It will calculate any big numbers and there is no overflow!</div>
    </div><!-- boxLeft-->    
    <div class="boxRight">
      <h2 id='3' class="boxRightH2">
        Enter two <b style="font-size: 150%">BIG</b> integer numbers (till your sore fingers)</h2>
      <div><span id='4'>First number: </span><input type="text" id="v1" class="inputNum" value="1234567899876543210" />
      </div>
      <div><span id='5'>Second number:</span><input type="text" id="v2" class="inputNum" value="987654321123456789" />
      </div>
      <div><input id='0b' type="button" class="button" onclick="calculate()" value="Calculate" /> <input id='1b' type="button" class="button" onclick="clearResult()" value="Clear" />
      </div>
      <br />
      <div id="result">
      </div>
    </div><!-- boxRight -->
  </div><!-- container -->
</body>
              
            
!

CSS

              
                body {
  font-size: 20px;
}

input {
  font-size: 100%;  
}

.button {
  font-size : 20px; 
  width: 140px;
  height: 35px; 
  background-color: #004990; 
  color: #e6e5e5; 
  border-radius: 8px;
}

textarea {
  font-size: 90%;
}

.container {
  border:2px solid;
  width:100%;
  float:left; 
}

select.topRightCorner {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 110px;
  border: 3px solid #004990;
}

.boxLeft  {
  float:left; 
  width:20%;
  border:1px solid;
  padding: 0 1% 1% 1%;
  margin:1% 0 1% 1%;
  color:green;
}

.boxLeftH2 {
   margin:0.5% 0% 5%;
}

.boxRight {
  float:right;
  margin: 1% %1 1% 1%;
  width:75%
}

.boxRightH2 {
  color: #004990;
  background-color: #e6e5e5;
}

.inputNum {
  width: 98%;
}

.result {
  width:98%;
  height:100%;
}
              
            
!

JS

              
                let textArray = [
  ['Information', '信息解釋'],
  ['Input two positive integer numbers and get the result of multiplication of those two numbers.','輸入兩個正整數,得到這兩個數的乘積結果。'],
  ['It will calculate any big numbers and there is no overflow!', '這個計算的結果可以是任何兩個大數的乘積結果,將不會出現溢出!'],
  ['Enter two <b style="font-size: 150%">BIG</b> integer numbers (till your sore fingers)', '輸入兩個<b style="font-size: 150%">大</b>正整數(敲到你手發酸)'],
  ['First number:', '第一個數字:'],
  ['Second number:', '第二個數字:'],
];

let buttonCaption = [
  ['Calculate', '計算'],
  ['Clear', '清除']
  ];

let resultLabels = [
  ['Calculated result:', '計算的結果:'],
  ['Infinity(overflow)','無法確定(溢出)'],
  ['Verified result:', '驗算的結果:']
]
var lanIndex = 0;

function debug(msg) {
  //if (!window.console) {
    console.log(msg);
  //}
}

function onSelect(elm) {
  lanIndex = elm.value;
  for (var i = 0; i < textArray.length; i++) {
    var e = document.getElementById(i + '');
    e.innerHTML = textArray[i][lanIndex];
  }
  for (var i = 0; i < buttonCaption.length; i++) {
  var e = document.getElementById(i + 'b');
    e.setAttribute('value', buttonCaption[i][lanIndex]);
  }
}

function addCommas(nStr) {
  nStr += "";
  x = nStr.split(".");
  x1 = x[0];
  x2 = x.length > 1 ? "." + x[1] : "";
  var rgx = /(\d+)(\d{3})/;
  while (rgx.test(x1)) {
    x1 = x1.replace(rgx, "$1" + "," + "$2");
  }
  return x1 + x2;
}

function adjustHeight() {
  let list = document.getElementsByTagName("textarea");
  for (let elm of list) {
    var sh = elm.scrollHeight;
    var h = elm.offsetHeight;
    if (h < sh) {
      elm.style.height = sh + "px";
    }
  }
}

function clearResult() {
  let elmID = 'result';
  var elm = document.getElementById(elmID);
  elm.innerHTML = '';
}

function showResult(elmID, text) {
  var fieldNameElement = document.getElementById(elmID);
  if (fieldNameElement) {
    fieldNameElement.innerHTML += text;
  }
}

function v1timesv2(v1, v2) {
  var x = ""; // result
  var i = 0;
  var j = 0;
  var r;
  var r1;
  var r2;
  var k;
  var tempVal;
  var preTempVal = "";
  debug("v1: " + v1);
  debug("v2: " + v2);
  for (
    i = v2.length - 1;
    i >= 0;
    i-- // v2
  ) {
    r2 = 0;
    tempVal = "";
    k = preTempVal.length;
    for (
      j = v1.length - 1;
      j >= 0;
      j-- // v1
    ) {
      if (k-- > 0) {
        r2 += Number(preTempVal[k]);
      }
      r = v1[j] * v2[i] + r2;
      r1 = r % 10;
      r2 = 0;
      if (r > 9) {
        r2 = (r - r1) / 10;
      }
      tempVal = r1 + tempVal;
    }
    if (r > 9) {
      tempVal = r2 + tempVal;
    }
    debug("intermediate calculated result: " + tempVal);
    // Get the last char as result
    x = tempVal[tempVal.length - 1] + x;
    debug("intermediate result: " + x);
    // Get the remaining as previous val
    if (tempVal.length > 1) {
      preTempVal = tempVal.substr(0, tempVal.length - 1);
    } else {
      preTempVal = "";
    }
    debug("== carry forward result: " + preTempVal + " ==");
  }
  x = preTempVal + x;
  debug(">>final result:    " + x);
  debug(
    ">>verified result: " +
      Number(v1) * Number(v2) +
      " (" +
      v1 +
      " x " +
      v2 +
      ")"
  );
  return x;
}

function calculate() {
  var x1 = document.getElementById("v1").value;
  var x2 = document.getElementById("v2").value;
  if (x1 == null || x1 == "" || x2 == null || x2 == "") {
    alert("nubmers must be filled out");
  } else {
    x1 = (x1 + "").replace(/^\s+|\s+$/g, "");
    x2 = (x2 + "").replace(/^\s+|\s+$/g, "");
    var x = v1timesv2(x1, x2);
    const textarea = '<textarea class="result" readonly>';
    const textareaEnd = "</textarea>";
    var i = 0;
    var content = resultLabels[i++][lanIndex] + "<br />" + textarea;
    content += addCommas(x + "");
    content += textareaEnd + "<br />";
    content +=
      textarea +
      "(" +
      x1 +
      " x " +
      x2 +
      ") = \n" +
      x +
      textareaEnd +
      "<br />";
    var x1x2;
    if ((x1 * x2) === Infinity) {
      x1x2 =  resultLabels[i][lanIndex]; 
    } else {
      x1x2 = (x1 * x2) + '';
    }
    i++;
    content +=  resultLabels[i][lanIndex] + "<code>" + x1x2 + "</code></><br /><br />";
    showResult("result", content);
    adjustHeight();
  }
}

              
            
!
999px

Console