Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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.

HTML

              
                <div id="numbers"></div>
<div class="cntr">
  <input id="try" type="text" />
  <span id="results" class="blur">= 21</span>
  <div class="instructions blur">
  Use arithmetic to combine all five numbers into 21.</div>
</div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Hammersmith+One');

body, input{
  font-family: 'Hammersmith One', sans-serif;
  font-size:32px;
  color:#333;
}

#numbers{
  width:33%;
  margin-left:33%;
  text-align:center;
}

  #numbers span{
    padding: 0 10px;
  }

input{
  width:33%;
  margin-left:33%;
  padding:2px 10px;
}

  .correct input{
    border: 4px solid rgb(51,196,68);
  }
  .incorrect input{
    border: 4px solid #E32F21;
  }

.blur{
  color:rgba(0,0,0,0.4);
}

.instructions{
  margin-top:20px;
  font-size:16px;
  text-align:center;
  position:relative;
}
  .correct .instructions, .incorrect .instructions{
    color:#fff;
  }
  .correct .instructions:after{
    content:'Great job!';
    top:0;
    left:47%;
    position:absolute;
    color:rgb(51,196,68);
  }

  .incorrect .instructions:after{
    content:'Only use the numbers given above!';
    top:0;
    left:43%;
    position:absolute;
    color:#E32F21;
  }
              
            
!

JS

              
                function getRand(){
  //make array of random nums
  const res = [1,1,1,1,1].map((e) => Math.ceil(e * Math.random() * 9));
  $('#numbers').html(res.map((e) => '<span>' + e + '</span>'));
  return res;
};

function handleInput(textInput){
  const res = math.eval(textInput);
  $('#results').html(res ? '= ' + res : '= 21')
    .toggleClass('blur', res != 21);
  $('.cntr').toggleClass('correct', $("#numbers span:not(.blur)").length == 0 && res == 21);
};

function blurNums(textInput){
  $("#numbers span").removeClass('blur');
  let nums = textInput.match(/\d+/g);
  $(nums).each(function(){
    $("#numbers span:not(.blur):contains('" + this + "')").first()
      .toggleClass('blur', $.inArray(parseInt(this),randNums) > -1);
  });
}

function handleCheaters(textInput){
  var nums = textInput.match(/\d+/g).sort();
  var usedNums = getUsedNums().toArray().sort();
  var incorrectNums = nums.filter((e,idx) => e != usedNums[idx]);
  $('.cntr').toggleClass('incorrect', incorrectNums.length > 0);
}

function getUsedNums(){
  return $("#numbers span.blur").map(function(){return parseInt(this.textContent)});
}

const randNums = getRand();

$('#try').on('input change',()=>{
  var textInput = $('input')[0].value;
  if(textInput){
    blurNums(textInput);
    handleInput(textInput);
    handleCheaters(textInput);
  } else{
    //clear off incorrect/correct styling when no input
    $('.cntr').removeClass('incorrect').removeClass('correct');
    $("#numbers span").removeClass('blur');
  }
});
              
            
!
999px

Console