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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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.


  <div class="field">
    <label for="attempts">Number of Attempts:</label>
    <input id="attempts" type="number" value="100" />
  <div class="field">
    <label for="switch">Switch Doors?</label>
    <input type="checkbox" id="switch" />
  <div class="field">
    <p id="result"></p>


                body {
  font-size: 16px;
  font-family: sans-serif;
  text-transform: uppercase;

.field {
  margin-bottom: 12px;
  border-bottom: 1px solid #ccc;
  padding: 16px;

button {
  font-size: 16px;
  font-family: sans-serif;
  text-transform: uppercase;

#result {
  padding-left: 16px;



                import * as _ from "";

function getDoorSetup() {
  const setup = ["goat", "goat", "car"];
  return _.shuffle(setup);

function getDoorPick() {
  const doorPick = _.random(0, 2);
  return doorPick;

function getGoatNotAtDoorNumber(setup, doorNumber) {
  let goatDoorNumber;

  setup.forEach((item, itemNumber) => {
    if (item === "goat" && itemNumber !== doorNumber) {
      goatDoorNumber = itemNumber;

  return goatDoorNumber;

function getFinalPick(ourPick, revealedPick, changePick) {
  if (!changePick) {
    return ourPick;

  const possibleDoorNumbers = [0, 1, 2];
  return possibleDoorNumbers.filter((doorNumber) => {
    if (doorNumber !== ourPick && doorNumber !== revealedPick) {
      return true;

function playGame(switchDoors) {
  const setup = getDoorSetup();
  const ourDoorPick = getDoorPick();
  const revealedGoatPosition = getGoatNotAtDoorNumber(setup, ourDoorPick);
  const ourFinalPick = getFinalPick(

  if (setup[ourFinalPick] === "car") {
    return 1;

  return 0;

function runSimulation() {
  const rounds = parseInt(document.querySelector("#attempts").value, 10);
  const doSwitch = document.querySelector("#switch").checked;

  let counter = 0;
  let wins = 0;

  while (counter < rounds) {
    const result = playGame(doSwitch);
    wins = wins + result;
    counter = counter + 1;

  const resultText = document.querySelector("#result");
  resultText.innerText = `Out of ${rounds} rounds, you win ${wins} games!`;

function main() {
  const button = document.querySelector("button");
  button.addEventListener("click", runSimulation);