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.

            
              <div class="container-fluid">
  <h1>cycleWorks</h1>
  <div class="row" id="inputs">
    <div class="col-lg-offset-1 col-lg-3 col-xs-6">
      <h3>workCycle</h3>
      <div class="cycle-input">
        <i class="fa fa-minus" id='work-minus'></i><span id='work-cycle'>25</span>
        <i class="fa fa-plus" id='work-plus'></i>
      </div>
    </div>
    <div class="col-lg-3 col-lg-push-4 col-xs-6">
      <h3>restCycle</h3>
      <div class="cycle-input">
        <i class="fa fa-minus" id='rest-minus'></i>
        <span id="rest-cycle">5</span>
        <i class="fa fa-plus" id='rest-plus'></i>
      </div>
    </div>
    <div class="col-lg-4 col-lg-pull-3 col-xs-12">
      <h3 id='messages'>cycleTimer</h3>
      <div id='timer'>
        25:00
      </div>
      <div id='timer-controls'>
        <i class="fa fa-lg fa-play" id="play"></i>
        <i class="fa fa-lg fa-pause" id="pause"></i>
        <i class="fa fa-refresh" id="reset"></i>
      </div>
    </div>
  </div>
</div>
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Comfortaa');
$uniformFont : 'Comfortaa', sans-serif;
$jet: rgb(51, 51, 51);
$taupe-gray: rgb(138, 138, 138);
$baby-powder: rgb(255, 255, 251);
$cadet-blue: rgb(92, 158, 173);
$black-coral: rgb(79, 93, 117);
/*Apply styles*/
*{
font-family: $uniformFont;
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
  background-color: $black-coral;
}
h1 {
  text-align: center;
  padding-bottom: 10px;
  color: $baby-powder;
}
h3 {
  text-align: center;
  color: $baby-powder;
}
.cycle-input {
  background-color: rgba($jet, .75);
  min-height: 100px;
  height: 100px;
  width: 100px;
  text-align: center;
  line-height: 100px;
  font-size: 1.5rem;
  color: $baby-powder;
  border-radius: 50px;
  overflow: hidden;
  margin-left: auto;
  margin-right: auto;
  i {
    padding: 0 5px;
  }
}
i:hover {
    cursor: pointer;
    color: $taupe-gray;
  }
.test {
  border: 2px solid white;
}
.test2 {
  border: 2px solid yellow;
}
#timer {
  min-height: 125px;
  height: 125px;
  width: 250px;
  border-radius: 50px;
  background-color: rgba($jet, .75);
  text-align: center;
  line-height: 125px;
  font-size: 4rem;
  font-weight: 700;
  color: $baby-powder;
  overflow: hidden;
  margin-left: auto;
  margin-right: auto;
  z-index: -1;
  position: relative;
}
#timer-controls {
  font-size: 1.5rem;
  color: $baby-powder;
  text-align: center;
  i {
    padding: 10px 15px;
  }
}



            
          
!
            
              //OBJECT CONSTRUCTOR FUNCTION WILL TAKE INPUTS WORK/REST CYCLES IN MINUTES, DISPLAY AND MESSAGE ELEMENT ID'S
var Pomodoro = function(workTime, restTime, displayId, messageId) {
  this.workCycle = workTime * 60;
  this.restCycle = restTime * 60;
  this.timeLeft = workTime * 60;
  this.prevState = 2; //STATES: 0-INITIAL, 1-PAUSED, 2-WORKCYCLE, 3-RESTCYCLE
  this.currState = 0;
  this.clockDisplay = displayId;
  this.messageDisplay = messageId;
};
//DEFINE METHODS TO UPDATE DISPLAY, UPDATE STATE, PLAY, PAUSE, RESET, AND ADJUST CYCLE TIMES
//DEFINE UPDATEDISPLAY METHOD TO BE USED IN OTHER METHODS
Pomodoro.prototype.updateDisplay = function(timeLeft) {
  //FUNCTION TO FORMAT TIME FOR DISPLAY
  function formatTime(timeSeconds) {
    var minsLeft = Math.floor(timeSeconds / 60),
      secondsLeft = timeSeconds - (minsLeft * 60);
    return (minsLeft < 10 ? '0' + minsLeft : minsLeft) + ":" + (secondsLeft < 10 ? '0' + secondsLeft : secondsLeft);
  }
  //UPDATE INNERTEXT
  document.getElementById(this.clockDisplay).innerText = formatTime(timeLeft);
};
//DEFINE UPDATESTATE METHOD TO BE USED IN OTHER METHODS
Pomodoro.prototype.updateState = function(newState) {
  if (newState === 0) {
    this.prevState = 2;
  } else {
    this.prevState = this.currState;
  }
  this.currState = newState;
  this.updateDisplay(this.timeLeft);
};
//DEFINE PLAY METHOD
Pomodoro.prototype.play = function() {
  var self = this; //CREATE LOCAL VARIABLE TO HOLD REFERENCE TO POMODORO OBJECT
  //DEFINE CLOCKTICK FUNCTION TO RUN OVER INTERVAL
  function clockTick() {
    if (self.timeLeft <= 0) {
      self.timeLeft = self.currState === 2 ? self.restCycle : self.workCycle; //SET TIMELEFT TO NEXT CYCLE
      self.updateState(self.currState === 2 ? 3 : 2);
    } else{
    self.timeLeft = self.timeLeft - 1;
    }
    self.updateDisplay(self.timeLeft);
  }
  if (this.currState === 0 ||  this.currState === 1) { //IF CURRENT STATE IS INITIAL OR PAUSED
    this.updateState(this.prevState === 2 ? 2 : 3); //CHECK PREV STATE TO UPDATE CURRENT STATE
    clockTick(); //FIRST CLOCK TICK IMMEDIATELY - CLOCKTICK DEFINED BELOW
    this.timerInterval = setInterval(function() {
      clockTick();
    }, 1000); //CREATE INTERVAL TO CLOCKTICK EVERY SECOND
  }
};
//DEFINE PAUSE METHOD
Pomodoro.prototype.pause = function() {
  if (this.currState === 2 || this.currState === 3) {
    this.updateState(1);
    clearInterval(this.timerInterval);
  }
};
//DEFINE RESET METHOD
Pomodoro.prototype.reset = function() {
  clearInterval(this.timerInterval);
  this.updateState(0);
  this.timeLeft = this.workCycle;
  this.updateDisplay(this.timeLeft);
};
//DEFINE UPDATE TIMES METHOD
Pomodoro.prototype.updateTimes = function (workCycle,restCycle){
  this.workCycle = workCycle*60;
  this.restCycle = restCycle*60;
  this.reset();
};
//INITIALIZE OUR POMODORO
var cycleWorks = new Pomodoro(25, 5, "timer", "messages");
//ASSIGN CYCLEWORKS METHODS TO DOM ELEMENTS-PLAY,PAUSE,RESET
var playId=document.getElementById("play"),
    pauseId=document.getElementById("pause"),
    resetId=document.getElementById("reset");
playId.addEventListener('click',function(){cycleWorks.play();});
pauseId.addEventListener('click',function(){cycleWorks.pause();});
resetId.addEventListener('click',function(){cycleWorks.reset();});
//COMPLETE FUNCTIONALITY OF UPDATING CYCLE LENGTHS USING UPDATETIMES METHOD
var workMinusId=document.getElementById("work-minus"),
    workPlusId=document.getElementById("work-plus"),
    workCycleId=document.getElementById("work-cycle"),
    restMinusId=document.getElementById("rest-minus"),
    restPlusId=document.getElementById("rest-plus"),
    restCycleId=document.getElementById("rest-cycle");
    
workMinusId.addEventListener('click',function(){
  if (parseInt(workCycleId.innerText)>1){
  workCycleId.innerText = parseInt(workCycleId.innerText) - 1;
  cycleWorks.updateTimes(workCycleId.innerText,restCycleId.innerText);
}
});
workPlusId.addEventListener('click',function(){
  workCycleId.innerText = parseInt(workCycleId.innerText) + 1;
  cycleWorks.updateTimes(workCycleId.innerText,restCycleId.innerText);
});
restMinusId.addEventListener('click',function(){
  if (parseInt(restCycleId.innerText)>=1){
  restCycleId.innerText = parseInt(restCycleId.innerText) - 1;
  cycleWorks.updateTimes(workCycleId.innerText,restCycleId.innerText);
}
});
restPlusId.addEventListener('click',function(){
  restCycleId.innerText = parseInt(restCycleId.innerText) + 1;
  cycleWorks.updateTimes(workCycleId.innerText,restCycleId.innerText);
});
            
          
!
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