123

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.

            
              .computer
  .output-wrapper
    #output
      #screen.screen
        | Welcome to the The Selectinator 3000!
        br
        br
        | press enter to start...
        br
        br
        span#text
        span#cursor.blink
  .computer-base
    #lights
      - var n = 0
      while n < 45
        span(class='light light-'+n)= n++
audio#audio(src='http://www.trekcore.com/audio/toscomputer/sequences/tos_sequence_19.mp3')
            
          
!
            
              * {
  box-sizing: border-box;
}
body {
  width: 100vw;
  height: 100vh;
  background: #ECF0F1;
  display: flex;
  direction: column;
}
.computer {
  z-index: 1;
  margin: auto;
  width: 340px;
}

.output-wrapper {
  margin: auto;
  padding: 20px;
  background: #C5C1A5;
  border-radius: 10px;
  position: relative;
  
  &:after, &:before {
    content: 'Compy 386';
    font-size: 11px;
    position: absolute;
    left: 40px;
    height: 10px;
    bottom: 5px;
    border-radius: 50%;
  }
  &:before {
    content: '';
    left: 22px;
    width: 10px;
    background: #646464;
  }
  #output {
    margin: auto;
    width: 300px;
    height: 250px;
    color: #01FF00;
    font-family: monospace;
    background: black;
    overflow: hidden;
    padding: 5px;
    position: relative;
    border-radius: 7px;
    &:before {
      content: '';
      position: absolute;
      width: 100%;
      height: 5px;
      z-index: 100;
      top: 0;
      left: 0;
      background: black;
    }
    .screen {
      position: absolute;
      transition: opacity 2s ease;
    }
    .blink {
      content: '';
      width: 7px;
      height: 10px;
      background: #01FF00;
      display: inline-block;
      animation: pulse 1s infinite;
    }
  }
}
.computer-base {
  background: #C5C1A5;
  height: 85px;
  border-radius: 10px;
  margin-top: 5px;
  padding: 15px;
}
#lights {
  display: flex;
  direction: row;
  flex-wrap: wrap;

  .light {
    width: 6%;
    height: 6%;
    background: #C0392B;
    text-indent: -999px;
    overflow: hidden;
    margin: .3%;
    display: inline-block;
    transition: all 300ms ease;
    
    &.on {
      background: lighten(#C0392B,30%);
    }
  }
}

@keyframes pulse {
  0% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}
            
          
!
            
              let terminal = document.getElementById('text'),
    output = document.getElementById('output'),
    screenEl = document.getElementById('screen'),
    lights = makeArray(document.getElementsByClassName('light')),
    counter = 0,
    playedOnce = false,
    winner = [
      "Millard Galarza","Bernadine Dix","Emery Brim","Petra Ricken","Tamica Lucht","Joanie Sabbagh","Lynnette Shanklin","Adrienne Bakos","Vern Lemke","Barney Hubert","Starla Fausnaught","Darrell Bankes","Rivka Puterbaugh","Adolph Murray","Cicely Peterman","Tona Linde","Tarra Castelli","Elnora Blahnik","Roseanna Hedberg","Marlys Oestreich","Kelly Draper","Teisha Dinatale","Brice Hackett","Emelda Levering","Drew Grimes","Georgetta Spivey","Kirby Ault","Laurice Welker","Columbus Volkmann","Suzette Pawloski","Xenia Nicolosi","Agatha Linehan","Antonio Miceli","Adelina Marko","Arla Tschida","Edna Amy","Jolynn Alba","Kathryne Tison","Tressie Dysart","Delinda Spiegel","Kristian Weakley","Annice Hymes","Joanne Meritt","Alton Ginter","Granville Puig","Tia Bonaparte","Marcelene Ruvalcaba","Tennille Tsosie","Tracie Westerlund","Cameron Lytch"
    ],
    letters = [
      'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
    ],
    // test that we put names through
    tests = [
      function letterCheck(name) {
        let letter = letters[Math.floor(Math.random() * letters.length)];
        return !!(name.indexOf(letter) > -1); // grab a random letter of alphabet, if you don't have that letter you're out
      },
      function randomCheck() {
        return !!Math.round(Math.random()); // 50/50 shot here
      },
      function lengthCheck(name) {
        let length = Math.floor(Math.random() * 25);
        return !!(name.length > length); // grab a random number between 0-25 if you're name is longer than that number you're out
      }
    ];

// this gets things started
// watch enter, when they press enter play audio and start testing names
document.onkeyup = keyUp;
function keyUp(e) {
  e = e || window.event;
  if (e.keyCode == '13' && playedOnce === false) {
    testName();
    document.getElementById('audio').play();
    playedOnce = true;
  }
}

// get passed in a string, delay, and current iterator
// based on that output text to the screen
// in future we should pass in element we are rendering to, that would make this more reusable
// also you can remove the first if, that's pretty specific to this situation
function typeText(text, time, i = 0) {
  if (terminal.style.bottom === '') {
    // if bottom isn't defined see if we need to start the scrolling effect
    screenScroll();
  }
  setTimeout(function(){
    // on first iteration of the string I'm making a new line
    // else we add to the line
    if (i === 0 && terminal.innerHTML != '' && text != ' you lose') {
      terminal.innerHTML += `<br /> ${text.charAt(i)}`;
    } else {
      terminal.innerHTML += text.charAt(i);
    }
    i++;
    if (text.length >= i) {
      typeText(text, time, i);
    }
  }, time);
}

// grab a random name and put them through a test
// based on win/fail we output text
function testName() {
  counter++; // counter is just for fun to know how many tests we do before finishing
  let index = [Math.floor(Math.random() * winner.length)], // do math to pick a random person from winners array
      name = winner[index];

  if (winner.length > 1) {
    let test = tests[Math.floor(Math.random() * tests.length)]; // do math to find what test we are going to do

    if (!(test(name))) {
      // if test returns false, you lose
      winner.splice(index,1); // remove them from array
      typeText(`${name}...`, 30);
      setTimeout(function(){
        typeText(` you lose`, 40);
      },1100);
      setTimeout(testName,2000); // test the next name
    } else {
      //typeText(`${name}... you pass`, 40);
      testName(); // test the next name
    }
  } else {
    // you are last person in array of names
    typeText(`${name}... you win :)`, 40);
    funResponses(); // just to make it fun we output more things
  }
}

/* figure out what block we're going to light up next */
(function nextLight() {
  let index = [Math.floor(Math.random() * lights.length)]; // math to grab a random element
  let light = lights[index];
  lightUp(light);
  setTimeout(nextLight,300);
})();

// take the el passed in an toggle a class
function lightUp(light) {
  light.classList.add('on');
  setTimeout(function(){
    light.classList.remove('on');
  },1000);
}

// switch screen to absolutely position bottom which makes it look more like a normal screen.
function screenScroll() {
  if (screenEl.offsetHeight >= output.offsetHeight - 5) {
    screenEl.style.bottom = '5px';
  }
}

function funResponses() {
  setTimeout(function(){
    typeText(`Total calculations: ${counter}`, 40);
  },2000);
  setTimeout(function(){
    typeText(`Thanks for playing!`,40);
  },8000);
  setTimeout(function(){
    typeText(`Why are you still here?`,100);
  },25000);
  setTimeout(function(){
    typeText(`Seriously you need to leave...`,100);
  },35000);
  setTimeout(function(){
    typeText(`Don't you have friends or places to be?`,100);
  },55000);
  setTimeout(function(){
    typeText(`Trogdor was a man. I mean, he was a dragon man! Er, maybe he was just a dragon! Um, but he was still TROGDOR! TROGDOR! Burninating the countryside, burninating the peasants! Burninating all the peoples who lived in THATCHED ROOFED COTTAGES! THATCHED ROOFED COTTAGES! And the Trogdor comes in the NIIIIIIGHT! `,40);
  },85000);
  setTimeout(function(){
    typeText(`..............................`,400);
  },142000);
  setTimeout(function(){
    typeText(`Well this is awkward...`,40);
  },202000);
  setTimeout(function(){
    typeText(`you just lost the game...`,40);
  },212000);
  setTimeout(function(){
    typeText(`bye...`,40);
  },222000);
  setTimeout(function(){
    screenEl.style.opacity = 0;
  },230000);
}

// helper functions
function makeArray(r){return[].slice.call(r,0)}; // takes an element query array and turns it into an actual usable array

// no longer need to break names into array as I'm inputting them as an array
// let splitThat = names.split('\n');
// let winner = [];
// for (let i in splitThat) {
//   winner[i] = splitThat[i].trim();
// }
// console.log(JSON.stringify(winner));
            
          
!
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