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.

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

              
                <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>
              
            
!

CSS

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

JS

              
                /* 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

Console