css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.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...
            
          
!
            
              *,
*: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;
    }
  }
}
            
          
!
            
              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
🕑 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.
Loading ..................

Console