Pen Settings

HTML

CSS

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

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

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.

HTML

              
                div(class="container")
  div(class="input")
    label(for="name") Name
    input(name="name", maxlength="7")
  div(class="input")
    label(for="currentCash") Current Cash
    input(name="currentCash", maxlength="6")
  div(class="input")
    label(for="id") ID
    input(name="id", maxlength="5")
  div(class="input")
    label(for="password") Password
    input(name="password", readonly)

              
            
!

CSS

              
                @import url(//fonts.googleapis.com/css?family=Ubuntu);
@import url(//fonts.googleapis.com/css?family=Ubuntu+Mono);

html, body {
  height          : 100%;
  width           : 100%;
}

body {
  align-items      : center;
  background-color : #9ACCF2;
  color            : #8828B0;
  display          : flex;
  font-family      : Ubuntu, sans-serif;
  margin           : 0 auto;
  padding          : 0;
}

.container {
  margin : auto;
}

.input {
  padding : 15px;
}

label {
  display   : block;
  font-size : 1.5em;
}

input {
  background-color : #9ACCF2;
  border           : 0;
  border-bottom    : solid 3px;
  color            : #8828B0;
  font-family      : "Ubuntu Mono", monospace;
  height           : 20px;
  width            : 125px;
  padding          : 10px 10px;
  font-size        : 1.25em;
}

input:focus {
  outline: none;
}

input[name="currentCash"], input[name="id"] {
  text-align: right;
}

::selection {
  background : #8828B0;
  color      : #9ACCF2;
}

              
            
!

JS

              
                (function() {
/***
 * Calculate the time reset code for Pokémon Crystal.
 * 
 * Purpose: Take the trainer's name, currently held cash, and ID
 *   number, returning a five digit ID number. 
 * 
 *  1) Map the first five characters of the trainer's name to an
 *     arbitrary set of numbers.
 *  2) Add those values together to get a single value.
 *  3) If the current cash is greater than 65535, get the modulus.
 *  4) Integer divide the current cash or modulus by 256.
 *  5) Add the modulus of that number and 256 to the result of the
 *     previous step.
 *  6) If the ID is greater than 65535, subtract the current
 *     cash from the ID until it is less than 65535.
 *  7) Integer divide the ID number or modulus by 256. 
 *  8) Add the modulus of that number and 256 to the result of the
 *     previous step.
 *  9) Zero pad the result from each input.
 */

var CALC = CALC || {};

CALC.magicValue = 65535;
CALC.inputNames = ["name", "currentCash", "id"];
CALC.inputs = {};
CALC.values = {};
CALC.charMap = {
  // Uppercase
    "A": 128, "B": 129, "C": 130, "D": 131, "E": 132, "F": 133, "G": 134
  , "H": 135, "I": 136, "J": 137, "K": 138, "L": 139, "M": 140, "N": 141
  , "O": 142, "P": 143, "Q": 144, "R": 145, "S": 146, "T": 147, "U": 148
  , "V": 149, "W": 150, "X": 151, "Y": 152, "Z": 153
  // Lowercase
  , "a": 160, "b": 161, "c": 162, "d": 163, "e": 164, "f": 165, "g": 166
  , "h": 167, "i": 168, "j": 169, "k": 170, "l": 171, "m": 172, "n": 173
  , "o": 174, "p": 175, "q": 176, "r": 177, "s": 178, "t": 179, "u": 180
  , "v": 181, "w": 182, "x": 183, "y": 184, "z": 185
};

CALC.outputName = "password";

/***
 * Pad a number with zeroes or a given character by a given amount.
 * http://stackoverflow.com/a/10073788/2305229
 ***/
CALC.pad = function(n, width, z)
{
  z = z || '0';
  n = n + '';
  return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
};

CALC.addHandlers = function(inputNames)
{
  for (var i = 0; i < inputNames.length; i++)
  {
    CALC.inputs[inputNames[i]] = document.getElementsByName(inputNames[i])[0];
    CALC.inputs[inputNames[i]].addEventListener(
         "keyup"
       , this.calculatePassword
       , false
     );
  }
};

CALC.getNameBasedValue = function(name)
{
  nameCharsLength = (name.length < 5 ? name.length : 5);
  nameChars = name.substring(0, nameCharsLength);
  nameVal = 0;
  for (var i = 0; i < nameCharsLength; i++)
  {
    nameVal = nameVal + CALC.charMap[nameChars[i]];
  }
  return nameVal;
};

CALC.getCashBasedValue = function(cash)
{
  cashVal = cash;
  if (CALC.magicValue < cash)
  {
    cashVal = cash % CALC.magicValue;
  }
  return ~~(cashVal/256) + cashVal % 256;
};

CALC.getIdBasedValue = function(id)
{
  idVal = CALC.adjustValueBelowThreshold(
        id
      , CALC.inputs.currentCash.value
      , CALC.magicValue
    );
  return ~~(idVal/256) + idVal % 256;
};

CALC.adjustValueBelowThreshold = function(value, adjustment, threshold)
{
  while (threshold < value)
  {
    value = value - adjustment;
  }
  return value;
};

CALC.calculatePassword = function(event)
{
  event.preventDefault;
  var password = 0;
  console.log(CALC.values.name);
  if (CALC.inputs.name.value.length > 0
    && CALC.inputs.currentCash.value.length > 0
    && CALC.inputs.id.value.length > 0)
  {
    CALC.values.name = CALC.getNameBasedValue(CALC.inputs.name.value);
    CALC.values.currentCash = CALC.getCashBasedValue(CALC.inputs.currentCash.value);
    CALC.values.id = CALC.getIdBasedValue(CALC.inputs.id.value);
    Object.keys(CALC.values).forEach(function(value) {
      password = password + CALC.values[value];
    });
    CALC.writePassword(password);
  }
};

CALC.writePassword = function(password)
{
  document.getElementsByName(this.outputName)[0].value = CALC.pad(password, 5);
};

CALC.init = function()
{
  this.addHandlers(this.inputNames);
  // document.getElementsByName("name")[0].focus();
};

CALC.init();
})();
              
            
!
999px

Console