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="flex">
      <div id="countdown" class="flex-center height-100" style="flex-grow: 1; min-width: 20%; background: black; color: white;">
        <h1 class="countdown-digit">10</h1>
      </div>
      <div class="flex-center height-100"  style="flex-grow: 3 ; padding: 0 30%; background: #DDD; ">
        <p>
          <form class="pure-form" id="submit-form" onSubmit="validateFormOnSubmit(); return false;" >

            <div class="js-options"></div>
            <!-- <label for="option1" aria-hidden="true" class="flex mt-1">
              <input type="checkbox" name="traps[]" id="option1" aria-hidden="true" class="mt-1 mr-1" value="Lorem ipsum dolor sit amet, consectetur a">
                Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
            </label>
            <label for="option2" aria-hidden="true" class="flex mt-1">
              <input type="checkbox" name="traps[]" id="option2" aria-hidden="true" class="mt-1 mr-1" value="Lorem ipsum dolor sit amet, consectetur a">
                Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
            </label>
            <label for="option3" aria-hidden="true" class="flex mt-1">
              <input type="checkbox" name="traps[]" id="option3" aria-hidden="true" class="mt-1 mr-1"  value="Lorem fsdfectetur a">
                Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
            </label>
            <label for="option1" aria-hidden="true" class="flex mt-1">
              <input type="checkbox" name="traps[]" id="option1" aria-hidden="true" class="mt-1 mr-1">
                Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
            </label> -->
            <div class="pure-controls">
              <button type="submit" class="pure-input-1 pure-button pure-button-primary">Enviar</button>
            </div>
          </form>
        </p>
      </div>
    </div>
              
            
!

CSS

              
                .flex {
    display: flex;
}

.flex-center {
    display: flex;
    justify-content: center;
    align-items: center;
}

.height-100 {
    height: 100vh;
}

.mt-1 {
    margin-top: 1em;
}

.mr-1 {
    margin-right: 1em;
}


/* Copy this @keyframes block to your CSS*/
@keyframes countdownAnimation {
    0.0% {
        background: black;
    }

    100% {
        background: red;
        opacity: 1;
    }


    69.8% {
        background: red;
        opacity: 0.5;
    }

    74.9% {
        background: red;
        opacity: 1;
    }

    80.3% {
        background: red;
        opacity: 0.5;
    }

    84.7% {
        background: red;
        opacity: 1;
    }

    89.3% {
        background: red;
        opacity: 0.5;
    }
}

/* Add the animation: property to whichever element you want to animate */
.countdown-danger {
    animation: countdownAnimation 5s ease 0s 1 normal forwards;
}
              
            
!

JS

              
                const SENTENCES = {
  bad: [
    "El mercado puede permanecer irracional más tiempo del que usted puede permanecer solvente.",
    "Un banco es un lugar que te presta dinero si puedes probar que no lo necesitas.",
    "El único presupuesto bueno es el presupuesto equilibrado.",
    "Nada tan esencial en los negocios como ser expeditivo.",
    "La audacia en los negocios es lo primero, lo segundo y lo tercero.",
    "El factor clave que va a determinar su futuro financiero no es la economía, el factor clave es su filosofía.",
    "La Economía es una disciplina narrativa y las explicaciones son fáciles de proporcionar a posteriori.",
    "Vale más asegurar un interés que ganar mil libras esterlinas.",
  ],
  good: [
    "¡Oh, memoria, enemiga mortal de mi descanso!",
    "Sábete, Sancho, que no es un hombre más que otro si no hace más que otro.",
    "El un lugar de la Mancha de cuyo nombre no quiero acordarme.",
    "A él (Sancho) le vino en voluntad y deseo de hacer lo que otro no pudiera hacer por él",
    "Don Quijote soy, y mi profesión la de andante caballería.",
    "¡Oh envidia, raíz de infinitos males y carcoma de las virtudes!",
    "Adonde interviene el favor y las dádivas, se allanan los riscos y se deshacen las dificultades.",
  ],
};


let timer = 10;

const random = (length) => Math.floor(Math.random() * length);

const pickSentences = () => {
  let picked = [];
  picked.push(SENTENCES["bad"][random(SENTENCES["bad"].length)]);
  picked.push(SENTENCES["bad"][random(SENTENCES["bad"].length)]);
  picked.push(SENTENCES["good"][random(SENTENCES["good"].length)]);
  picked.push(SENTENCES["good"][random(SENTENCES["good"].length)]);
  return picked;
};

const randomize = (array) =>
  array
    .map((a) => ({ sort: Math.random(), value: a }))
    .sort((a, b) => a.sort - b.sort)
    .map((a) => a.value);

const uniqueId = () => Math.random().toString(36).substr(2, 9);

const isGoodSentence = (sentence) => SENTENCES.good.some((s) => sentence == s);

const checkboxTemplate = (sentence) => {
  return `<label for="option${uniqueId()}" aria-hidden="true" class="flex mt-1">
          <input type="checkbox" name="traps[]" id="option${uniqueId()}" aria-hidden="true" class="mt-1 mr-1" value="${sentence}">
            ${sentence}
        </label>`;
};

const validateForm = () => {
  let traps = document.querySelectorAll('[name="traps[]"]:checked');
  if (traps.length != 2) {
    return false;
  }
  let validates = [...traps].filter((e) => isGoodSentence(e.value));

  if (validates.length !== 2) {
    return false;
  }
  return true;
};

const init = () => {
  randomize(pickSentences()).map((sentence) => {
    let el = document.createElement("span");
    el.innerHTML = checkboxTemplate(sentence);
    document.getElementsByClassName("js-options")[0].appendChild(el);
  });
};

init();

/*
document
  .getElementById("submit-form")
  .addEventListener("submit", function (evt) {
    evt.preventDefault();
    if (validateForm()) {
      alert("¡Pardiez! Un Humano");
    } else {
      alert("Alejate de mi ser infesto bot");
    }
  });
*/
const validateFormOnSubmit = () => {
    if (validateForm()) {
      alert("¡Pardiez! Un Humano");
    } else {
      alert("Alejate de mi ser infesto bot");
    }
  return false;
}

const changeBackgroundColor = (timer) => {
  if (timer == 5) {
    document.getElementById("countdown").classList.add("countdown-danger");
  }
};

var interval = setInterval(function () {
  timer--;
  changeBackgroundColor(timer);
  document.getElementsByClassName("countdown-digit")[0].innerHTML = timer;
  // if (timer === 0) {
  //   console.log("interval", interval);
  // }
}, 1000);

setTimeout(() => {
  clearInterval(interval);
  document.querySelector("button").disabled = true;
  //alert("¡Malandrín! Más rápido con tu sable debes de ser.");
}, 10000);

              
            
!
999px

Console