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


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.


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.


                残りやり取り数 <span id="rest"></span>
<ul id="result">
  <li id='a'></li>
  <li id='b'></li>
  <li id='c'></li>
  <li id='d'></li>
  <li id='e'></li>
  <li id='f'></li>

  やり取り回数 <input id="number-to-try" type="number" value="150"></input> 回でやり直す
  <button id="restart" type="button">restart</button>






                let task = null;


document.querySelector("#restart").addEventListener("click", start);

function start() {
  const current = [5, 5, 5, 5, 5, 5];
  const numberToTry = parseInt(document.querySelector("#number-to-try").value);
  run(current, numberToTry);

function run(current, count) {
  if (count === 0) {

  const { source, dest, result } = roleDiceAndMoveCoin(current);
  show(count, result);

  if (task) clearTimeout(task);
  task = setTimeout(() => run(result, --count), 30);

function show(count, result) {
  document.querySelector("#rest").innerText = count - 1;
  document.querySelector("#a").innerText = result[0];
  document.querySelector("#b").innerText = result[1];
  document.querySelector("#c").innerText = result[2];
  document.querySelector("#d").innerText = result[3];
  document.querySelector("#e").innerText = result[4];
  document.querySelector("#f").innerText = result[5];

function roleDiceAndMoveCoin(current) {
  const source = Math.floor(Math.random() *  6);
  const dest = Math.floor(Math.random() * 6);

  if (current[source] === 0 || source === dest) {
    return {
      result: current

  return {
    result:, index) => {
      if (index === source) {
        return val - 1;

      if (index === dest) {
        return val + 1;

      return val;