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.card
  div.rules Pick 6 numbers and hit play.
  div.nums
    - for i in (1 .. 49)
      div.num
        input id="n#{i}" name="n" type="checkbox" value="#{i}"
        label for="n#{i}" #{i}
  button.play Play

div.stats
  div.stat.stat--spending
    div.label 
      | Spending 
      div.sub $5 per play
    div.value $0
  div.stat.stat--weeks
    div.label 
      | Weeks
      div.sub One play per week
    div.value 0
    
div.results Pending start...
              
            
!

CSS

              
                *,
*:before,
*:after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}
body {
  background: url(https://image.freepik.com/free-photo/wooden-texture_1208-334.jpg) no-repeat;
  background-size: cover;
}

.card {
  box-shadow: 0 2px 10px rgba(0,0,0,.75);
  margin: 50px auto 30px;
  position: relative;
  width: 280px;
  
  &.locked {
    .num {
      input:not(:checked) {
        pointer-events: none;
        
        + label {
          opacity: .5;
          pointer-events: none;
        }
      }
    }
  }
  
  .rules {
    background: white;
    font-size: 14px;
    padding: 15px 20px;
  }

  .nums {
    background: #FDE3C7;
    display: flex;
    flex-wrap: wrap;
    padding: 20px;
  }

  .num {
    background: #FEF3E8;
    border: 4px solid #F57F65;
    color: #F57F65;
    margin: 4px;
    position: relative;
    width: calc(20% - 8px);
    
    label {
      display: flex;
      font-size: 16px;
      justify-content: center;
      padding: 5px;
    }
 
    input {
      appearance: none;
      cursor: pointer;
      height: 100%;
      opacity: 0.1;
      position: absolute;
      width: 100%;
      
      &:checked + label {
        background: #4E5560;
        color: white;
      }
    }
  }
}

.stats {
  color: white;
  display: flex;
  margin: 0 auto;
  padding: 0 30px;
  width: 280px;
  
  .stat {
    width: 50%;
    text-shadow: 0 2px 3px rgba(0,0,0,0.8);
    
    &--spending {
      width: 70%;
    }
  }
  
  .label {
    font-size: 18px;
    line-height: 1.3;
    margin-bottom: 10px;
    opacity: 0.9;
    
    .sub {
      font-size: 10px;
    }
  }
  
  .value {
    font-size: 32px;
    font-weight: bold;
  }
}

.play {
  appearance: none;
  background: #888 url(https://thumbs.gfycat.com/BeautifulExhaustedHippopotamus.webp) no-repeat;
  background-size: 75%;
  background-position: 300% 300%;
  bottom: 10px;
  border: none;
  border-radius: 50%;
  color: #999;
  cursor: not-allowed;
  display: inline-block;
  font-size: 18px;
  letter-spacing: .15em;
  height: 70px;
  overflow: hidden;
  position: absolute;
  right: -45px;
  text-transform: uppercase;
  transform: rotate(-10deg);
  width: 70px;
  
  &:focus {
    outline: none;
  }
  
  &.active {
    background-color: #7DC672;
    box-shadow: 0 2px 3px rgba(0,0,0,.6);
    color: white;
    cursor: pointer;
  }
  
  &.starting {
    background-position: center center;
    text-indent: 200%;
  }
}

.results {
  background: rgba(0,0,0,.5);
  border: 1px solid rgba(255,255,255,.1);
  color: white;
  font-size: 10px;
  margin: 40px auto 20px;
  max-height: 60px;
  opacity: .9;
  overflow: auto;
  padding: 15px 20px;
  width: 280px;
  
  .result {
    margin-top: 15px;
    
    .won {
      color: #8CDE80;
    }
    
    .loss {
      color: #F57F65;
    }
  }
}
              
            
!

JS

              
                var cost = 5;
var weeks = 0;
var myN = [];
var rounds = 9999;
var tWeeks = 0;
var tSpending = 0;

var start = function(state) {
  if (state) {
    $('.card').addClass('locked');
    $('.play').addClass('active').on('click', play);
  } else {
    $('.card').removeClass('locked');
    $('.play').removeClass('active').off('click');
  }
}

var reset = function() {
  weeks = 0;
  rounds = 9999;
  $('.results').html('Starting...');
}

var rollTheDice = function() {
  var newNum = [];
  
  while (newNum.length < 6) {
    var num = Math.floor((Math.random() * 49) + 1);
    
    if (!newNum.includes(num)) {
      newNum.push(num);
    }
  }
  
  newNum.sort(function(a, b) {
    return a < b ? -1 : a > b ? 1 : 0;
  });

  return newNum;
};

var formatSpending = function(value) {
  if (value > 1000000) {
    return (value / 1000000).toFixed(2) + 'm';  
  } else if (value > 99999) {
    return Math.floor(value / 1000) + 'k';  
  }

  return value;
}

var formatWeeks = function(value) {
  if (value > 99999) {
    return Math.floor(value / 1000) + 'k';
  }
  return value;
}

var play = function() {
  $('.play').addClass('starting');
  reset();

  var nums = Array.apply(null, { length: rounds }).reduce(function(all, i) {
    all.push(JSON.stringify(rollTheDice()));
    return all;
  }, []);
  
  setTimeout(function() {
    myN.sort(function(a, b) {
      return a < b ? -1 : a > b ? 1 : 0;
    });
    var myNjson = JSON.stringify(myN);
    var won = false;
    var spending = 0;

    while (!won && rounds > 0) {
      won = myNjson === nums[rounds] ? true : won;
      weeks++;
      rounds--;
    }

    var spending = weeks * cost;
    tSpending += spending;
    tWeeks += weeks;
    var formattedNums = '';

    nums.forEach(function(num) {
      formattedNums += '<div>' + num + '</div>';
    });
    $('.results').append(formattedNums);

    $('.stat--spending .value').html('$' + formatSpending(tSpending));
    $('.stat--weeks .value').html(formatWeeks(tWeeks));

    var $result = $('<strong>').addClass(won ? 'won' : 'loss').html(won ? 'Won' : 'Not won');

    $('.results')
      .append('<div class="result">After ' + weeks + ' weeks and $' + spending + ' you have ' + $result.prop('outerHTML') + '.</div>')
      .scrollTop($('.result').offset().top);
    $('.play').removeClass('starting');
  }, 100);
}

$('input[name="n"]').on('change', function() {
  var val = parseInt($(this).val());
  if ($(this).is(':checked')) {
    myN.push(val);
  } else {
    myN.splice(myN.indexOf(val), 1);
  }
  
  if (myN.length === 6) {
    start(true);
  } else {
    start(false);
  }
});
              
            
!
999px

Console