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 id="container">
  <div id="question">___</div>
  <div id="buttonSection">
    <div id="yesNo">
      <div class="button" onclick="Yes()">Yes</div>
      <div class="button" onclick="No()">No</div>
    </div>
    <div id="text" style="display:none">
      <input type="text" id="answer" />
      <div class="button" onclick="Answer()">Submit</div>
    </div>
  </div>
</div>
<a id="credit" href="https://skidsdev.xyz">Created by Dylan Renwick</a>
            
          
!
            
              body {
  margin: 0;
  overflow: hidden;
  font-family: helvetica, arial;
}

#question {
  display: block;
  margin: 0 auto;
  font-size: 48px;
  font-weight: bold;
  width: 600px;
  text-align: center;
  margin-top: 20%;
  margin-bottom: 10%;
}

#buttonSection {
  display: block;
  margin: 0 auto;
  font-size: 24px;
  font-weight: bold;
  width: 600px;
  text-align: center;
}

.button {
  width: 100px;
  display: inline-block;
  background: #ddd;
  margin: 0 20px;
  height: 30px;
  padding: 10px;
  border: 3px solid black;
  border-radius: 10px;
  cursor: pointer;
}

#answer {
  font-size: 24px;
  height: 30px;
  border-radius: 10px;
}

#credit {
  position: absolute;
  top: 0;
  left: 0;
  text-decoration: none;
  font-weight: bold;
}
            
          
!
            
              class Node {
  constructor(value, n1, n2) {
    if (n1 || n2) this.nodes = [n1, n2];
    else this.nodes = [];
    this.value = value;
  }
  
  replace(val, newNode) {
		if (this.nodes.length == 0) return false;
		if (this.nodes[0] !== null && this.nodes[0].value == val) {
			this.nodes[0] = newNode;
			return true;
    }
		if (this.nodes[1] !== null && this.nodes[1].value == val) {
			this.nodes[1] = newNode;
			return true;
    }
		if (this.nodes[0] !== null) {
			if (this.nodes[0].replace(val, newNode)) return true;
			if (this.nodes[1] !== null) return self.nodes[1].replace(val, newNode);
    }
  }
}

var node = new Node("a Pangolin", null, null);
var n = node;
var ansCallback = null;

window.addEventListener('load', () => {
  document.getElementById("container").style.width = window.innerWidth;
  document.getElementById("container").style.height = window.innerHeight;
  Play();
});

function Play() {
  noInput();
  print("OK, please think of an object, person, item, animal. Think of <i>something</i>");
  setTimeout(() => {
    Round(node, PlayCB);
  }, 3500);
}
             
function PlayCB(result) {
  if (result > 1) {
    if (result === 2) print("Good. That was soooo easy.");
    End();
  } else Round(n.nodes[result], PlayCB);
}

function Round(n, cb) {
	if (n.nodes.length == 0) {
		print("Is it " + n.value);
		readBool((response) => {
      if (response) cb(2);
      else {
        print("Oh. Well you win then -- What were you thinking of?");
        readText((answer) => {
          print(`Please give me a question about ${answer}, so I can tell the difference between ${answer} and ${n.value}`);
          readText((question) => {
            print(`What is the answer for ${answer}?`);
            readBool((ans) => {
              noInput();
              print("Thanks");
              if (ans === true) {
                newNode = new Node(question, new Node(answer, null, null), n);
              } else {
                newNode = new Node(question, n, new Node(answer, null, null));
              }
              if (node.value == n.value) node = newNode;
              else node.replace(n.value, newNode);
              setTimeout(() => cb(3), 2500);
            });
          });
        });
      }
    });
  } else {
		print(n.value);
    readBool((response) => {
      if (response) cb(0);
      else cb(1);
    });
  }
}

function End() {
  print("Would you like to play again?");
  readBool((v) => {
    if (v) Play();
    else print("Goodbye!");
  });
}

function noInput() {
  document.getElementById("yesNo").style.display = "none";
  document.getElementById("text").style.display = "none";
}

function readBool(fnc) {
  ansCallback = fnc;
  document.getElementById("yesNo").style.display = "block";
  document.getElementById("text").style.display = "none";
}

function readText(fnc) {
  ansCallback = fnc;
  document.getElementById("yesNo").style.display = "none";
  document.getElementById("text").style.display = "block";
}

function Yes() {
  if (ansCallback === null) return;
  ansCallback(true);
}

function No() {
  if (ansCallback === null) return;
  ansCallback(false);
}

function Answer() {
  if (ansCallback === null) return;
  let input = document.getElementById("answer");
  let value = input.value;
  input.value = "";
  ansCallback(value);
}

function print(msg) {
  document.getElementById("question").innerHTML = msg;
}

            
          
!
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