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.

            
              <header>
  <h1> Pomodoro Timer </h1>
  <p> Set a break and session length. If you'd like to start with a break, set the break last. Reset by pausing and changing the time.
</header>

<section class="controls">
  <div id="break" class="control">
    <div class="control-title">break length</div>
    <div class="control-updown">
      <button class="minus-break-length">-</button>
      <div id="break-length-value"> 5 </div>
      <button class="plus-break-length">+</button>
    </div>
  </div>
  </div>
  <div id="session" class="control">
    <div class="control-title">session length</div>
    <div class="control-updown">
      <button class="minus-session-length">-</button>
      <div id="session-length-value"> 25 </div>
      <button class="plus-session-length">+</button>
    </div>
  </div>
  </div>
</section>


<section id="timer" class="timer">
  <div class="circle">
    <div id="label" class="session">Session</div>
    <div id="time" class="session">25</div>
  </div>
</section>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Indie+Flower);
@import url(https://fonts.googleapis.com/css?family=Lato);
body {
  text-align: center;
  margin: 0 auto;
  background-color: #409999;
  color: #fff;
  font-family: 'Lato', sans-serif;
}

h1,
h2,
h3,
h4,
h5 {
  font-family: 'Indie Flower', cursive;
  font-weight: 800;
}

h1 {
  font-size: 90px;
}

.control {
  text-transform: uppercase;
  display: inline-block;
  margin: 1em;
  padding: 0;
}

.control-title {
  font-size: 13px;
}

#break-length-value {}

.control-updown {
  font-size: 24px;
}

.control-updown div {
  display: inline;
}

button {
  background-color: #409999;
  border-width: 0;
}
/* 2 ways to center things within a circle:
1) line-height: height/lines
2) display: table-cell;
   vertical-align: middle;
*/

.circle {
  border: 3px solid pink;
  border-radius: 50%;
  width: 300px;
  height: 300px;
  padding: 50px;
  line-height: 100px;
  margin: 0 auto;
  /* centering */
  
  cursor: pointer;
}

.session {
  font-size: 50px;
  font-weight: 300;
}

#label {
  text-transform: capitalize;
}
            
          
!
            
              /* Timer */
var Time = function(minutes) {
  var seconds = 0;
  var minutes = minutes;

  /* Assumes positive values */
  this.setTime = function(value) {
    minutes = value;
    seconds = 0;
  };

  this.getTime = function() {
    if (seconds < 10)
      return minutes + ":0" + seconds;
    return minutes + ":" + seconds;
  };

  this.decrement = function() {
    seconds--;
    if (seconds < 0) {
      minutes--;
      seconds = 59;
    }
  };
  this.isEmpty = function() {
    if (minutes <= 0 && seconds <= 0) {
      return true;
    }
    return false;
  };
};

var Mode = function() {
  var curMode = 0;
  var modes = ['session', 'break'];

  this.setMode = function(newMode) {
    curMode = modes.indexOf(newMode);
    // update the label
    $('#timer #label').text(mode.getMode());
  }

  this.changeMode = function() {
    if (++curMode > modes.length) {
      curMode = 0;
    }
    // update the label
    $('#timer #label').text(mode.getMode());
  };

  this.getMode = function() {
    return modes[curMode];
  };
};

/* Keep track of our timer and if it's running */
var running = false;
var timer = 0;
var time = new Time($("#session-length-value").text());
var mode = new Mode();

/* Limit the time selection to resonable amounts */
function bound(value) {
  if (value < 1) return 1;
  if (value > 100) return 100;
  return value;
}

/* Make the buttons increment/decrement the value */
/* note: could probably have generalized this */

$("#break button.minus-break-length").click(function() {
  if (running) return;
  var value = $("#break-length-value").text();
  $("#break-length-value").text(bound(--value));
  mode
});

$("#break button.plus-break-length").click(function() {
  if (running) return;
  var value = $("#break-length-value").text();
  $("#break-length-value").text(bound(++value));
});

$("#session button.minus-session-length").click(function() {
  if (running) return;
  var value = $("#session-length-value").text();
  value = bound(--value);
  $("#session-length-value").text(value);
});

$("#session button.plus-session-length").click(function() {
  if (running) return;
  var value = $("#session-length-value").text();
  value = bound(++value);
  $("#session-length-value").text(value);
});

$("#break").click(function() {
  if (running) return;
  mode.setMode("break");
  var value = $("#break-length-value").text();
  $("#time").text(value);
  time.setTime(value);
});

$("#session").click(function() {
  if (running) return;
  mode.setMode("session");
  var value = $("#session-length-value").text();
  $("#time").text(value);
  time.setTime(value);
})

function countDown() {
  time.decrement()

  // decrement time by 1 second & draw the new time
  $("#time").text(time.getTime());

  // check for end
  if (time.isEmpty()) {

    // stop current timer 
    clearInterval(timer);

    // play sound (can't upload assests)

    // change modes
    mode.changeMode();

    // Setup new time
    value = $("#" + mode.getMode() + "-length-value").text();
    time.setTime(value);

    //being the new timer
    timer = setInterval(countDown, 1000);

  }

};

$("#timer .circle").click(function() {

  if (!running) {
    timer = setInterval(countDown, 1000);
  } else {
    clearInterval(timer);
  }
  running = !running;

});
            
          
!
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