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.

            
              .container
  .result
    .score_board
      span.label score
      span.score 0
  .field_container
    .field
      .point
.home
  .message Click the white point.
  label
    span Level.
    span.level
    input#level(type="range", max="3", min="1", value="1")
  button#start Start
            
          
!
            
              *
  box-sizing: border-box
html, body
  background: white
  height: 100%
  width: 100%
.container
  height: 100%
  width: 100%
  display: flex
  flex-direction: column
  .result
    padding: 0.2em
    .score_board
      text-align: center
      .label
        margin-right: 1em
      .score
        display: inline-block
        width: 10em
.field_container
  background: #cccccc
  width: 100%
  height: 100%
  display: flex
  padding: 1em
  .field
    position: relative
    width: 100%
    background: black
    box-shadow: 0 0 0.5em 0.5em rgba(black, 0.3)
    .point
      position: absolute
      background: white
      border-radius: 50%
.home
  background: black
  height: 100%
  width: 100%
  position: absolute
  top: 0
  left: 0
  display: flex
  flex-direction: column
  align-items: center
  justify-content: space-around
  color: white
  .message
    font-size: 200%
  label
    display: flex
    justify-content: center
    align-items: center
    span.level
      margin-right: 1em
  #start
    border: none
    background: #007AB7
    color: white
    font-size: 200%
    padding: 0.5em 3em
    &:hover
      background: lighten(#007AB7, 10%)
            
          
!
            
              var count = 3;
var challenge_count = count;
var score_offset = 10000
var start = null;
var level;
var container = $('.field')
var point = $('.point');
var score = 0;

var init = function(){
  $("#level").val(1).change();
  count = challenge_count;
  score = 0;
  set_score();
}

$("#level").on('change', function(){
  level = $(this).val();
  $('span.level').text(level);
})

$('#start').on('click', function(){
  var size = 4 - level;
  point.css({height: size, width: size})
  $('.home').hide()
  
  recalc();
})

point.on('click', function(){
  var now = new Date()
  if(start != null){
    score += score_offset - (now - start)
    set_score();
  }
  
  setTimeout(function(){
    recalc();
  }, 1);
})

var recalc = function(){
  count--;
  if(count < 0){
    alert("Your score is " + score * level + "!!!\n\n" +
          "Level: " + level + "\n\n" +
          "Challenge count: " + challenge_count + "\n\n" +
          "Click to reload.")
    $('.home').show();
    init();
  }

  start = new Date()
  point.css({
    left: Math.random() * container.outerWidth(),
    top: Math.random() * container.outerHeight(),
  })
}

var set_score = function(){
  $(".score").text(score);
}

init();
            
          
!
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