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.

            
              <html>
<head>
  <title>Pomodoro Clock</title>
</head>
<body onload="defStart()">
  <h1 class ="text-center">Pomodoro Clock</h1>
  <div class = "text-center" id="options">   
    
    <div class = "choiceDiv text-center">      
      <h2>BREAK LENGTH</h2>
      <div class = "selectDiv">
        <button onclick="breakLess(); pauBreakLess()" id="minus">-</button>
        <p id="breakTime"></p>
        <button onclick="breakMore(); pauBreakMore()" id="plus">+</button>
      </div><!--selectDiv 1-->  
    </div><!--choiceDiv 1-->
    
    <div class = "choiceDiv text-center">      
      <h2>SESSION LENGTH</h2>
      <div class = "selectDiv">
        <button onclick="sessionLess(); pauSessLess()">-</button>
        <p id="sessionTime"></p>
        <button onclick="sessionMore(); pauSessMore()">+</button>
      </div><!--selectDiv 2-->  
    </div><!--choiceDiv 2-->        
  </div><!--options-->

  <div class="text-center">
    <span id="current"></span>      
    </br>
    <span id="time"></span>
  </div>
    
  <button id="pieButton" onclick="countStart(); pauseTime()">
    <div class="pie degree">       
    </div>
  </button>  
  
</body>
</html>

            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Righteous);
@import url(https://fonts.googleapis.com/css?family=Quicksand:300,400,500,700);

body{
  background:#2C3539;
  color:white;
  font-family:Quicksand, sans-serif;
  font-weight:300;
}

h1{
  margin-top:30px;
  font-family:Righteous, sans-serif;
  font-size:4em;
}

h2{
   font-weight:300;
   font-size:1.3em;
  
}

#options{
  display:flex;
  justify-content:center;
}

.choiceDiv{
  padding:0px 50px 10px 50px;
}

.selectDiv{
  display:flex;
  justify-content:space-between;
  align-items:center;
  font-size:1.5em;
}

#breakTime, #sessionTime{
  margin:auto;
}

button,button:focus{
  margin:auto;
  border:none;
  background:none;
  appearance: none;
  box-shadow:none;
  outline:none;
}

#current{
  font-size:2em;
}

#time{
  font-size:2em;
}

#pieButton{
    display: block;
    position: relative;
    margin: 20px auto 20px auto;
}

.pie{
    width: 180px;
    height: 180px;  
    border-radius: 50%;
    background-color: green;
    border-width:4px; 
    border-style:solid;
    border-color:green; 
 }

.degree{
      background-image:
        linear-gradient(90deg, transparent 50%, #2C3539 50%),
        linear-gradient(90deg, #2C3539 50%, transparent 50%);
}
            
          
!
            
              var breakL = 5;
var sessL = 25;
var countD = 0;
var curr = "SESSION";
var sessOn = false;
var countOn = false;
var totaltime;
var col;
var count = 0;
var counting = false;
var pause = false;
var breakClicked = false;
var sessClicked = false;

//Defualt settings for when document loads
function defStart(){
  document.getElementById("breakTime").innerHTML= breakL;
  document.getElementById("sessionTime").innerHTML= sessL;
  document.getElementById("current").innerHTML= curr;
  document.getElementById("time").innerHTML= sessL;
}

//Break length becomes less when its button is pressed at the beggining
function breakLess(){ 
  if(breakL > 1 && countOn == false || counting == false && countOn == true){
    breakL--;
    document.getElementById("breakTime").innerHTML= breakL;
    if(curr == "BREAK"){
      document.getElementById("current").innerHTML= curr;
      document.getElementById("time").innerHTML= breakL;     
    }    
  }
}
//Break length becomes less when its button is pressed during a pause
function pauBreakLess(){   
   breakClicked = true;  
  if(breakL > 1 && countOn == true && pause == true){   
      breakL--;
      document.getElementById("breakTime").innerHTML= breakL;   
  }  
  if (curr == "BREAK"){
    document.getElementById("time").innerHTML= breakL;
  }
  
}
//Break length becomes more when its button is pressed at the beggining
function breakMore(){
  if(breakL < 740 && countOn == false || counting == false && countOn == true){
    breakL++;
    document.getElementById("breakTime").innerHTML= breakL;
    if(curr == "BREAK"){
      document.getElementById("current").innerHTML= curr;
      document.getElementById("time").innerHTML= breakL;      
    }
  }
}
//Break length becomes more when its button is pressed during a pause
function pauBreakMore(){
    breakClicked = true;
    if(breakL < 740 && countOn == true && pause == true){   
      breakL++;
      document.getElementById("breakTime").innerHTML= breakL; 
      if (curr == "BREAK"){
        document.getElementById("time").innerHTML= breakL;
      }
    }  
}
//Session length becomes less when its button is pressed at the beggining
function sessionLess(){
  if(sessL > 1 && countOn == false){
    sessL--;
    document.getElementById("sessionTime").innerHTML= sessL;
    if(curr == "SESSION"){
      document.getElementById("current").innerHTML= curr;
      document.getElementById("time").innerHTML= sessL;      
    }
  }
}
//Session length becomes less when its button is pressed during a pause
function pauSessLess(){
     sessClicked = true;
    if(sessL > 1 && countOn == true && pause == true){   
      sessL--;
      document.getElementById("sessionTime").innerHTML= sessL;   
      if (curr == "SESSION"){
        document.getElementById("time").innerHTML= sessL;
      }
    }  
}
//Session length becomes more when its button is pressed at the beggining
function sessionMore(){
  if(sessL < 740 && countOn == false){
    sessL++;
    document.getElementById("sessionTime").innerHTML= sessL;
    if(curr == "SESSION"){
      document.getElementById("current").innerHTML= curr;
      document.getElementById("time").innerHTML= sessL;      
    }
  }
}
//Session length becomes more when its button is pressed during a pause
function pauSessMore(){
      sessClicked = true;
    if(sessL < 740 && countOn == true && pause == true){   
      sessL++;
      document.getElementById("sessionTime").innerHTML= sessL; 
       if (curr == "SESSION"){
          document.getElementById("time").innerHTML= sessL;
       }
    }
}

//Converts time to hours, minutes and seconds and inserts it into the html
function timeLoad(inp){
  var hours = Math.floor((inp % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  var minutes = Math.floor((inp % (1000 * 60 * 60)) / (1000 * 60));
  var seconds = Math.floor((inp % (1000 * 60)) / 1000);  
  //Adds '0' if minutes or seconds below 1
  if(minutes < 10){
    minutes = '0' + minutes;
  }
  if(seconds < 10){
    seconds = '0'+ seconds;
  }
  //Inserts time into html
  document.getElementById("time").innerHTML= hours + ':' + minutes + ':' + seconds;
}

//Sets the timer at its beginning before counting starts
function timerSet(inp){
  if (pause == false){
    timeLoad(inp)
    countD-=1000;
  }
}

//Pause and unpause time
function pauseTime(){
  //Pause
  if (pause == false && countOn == true && counting == true){   
    pause = true;
    counting = false;
   }
  //Unpause and restart counter
  else if (pause == true && countOn == true && counting == true){
    pause = false;
    counting = true;
    counter();
    
  //Unpause if break time was edited
    if (curr == "BREAK" && breakClicked == true){
      update(0);
      reset(breakL);
    }  
  //Unpause if session time was edited
    if (curr == "SESSION" && sessClicked == true){
        update(0);
        reset(sessL);
    }
  }  
}
 
//Resets the time display and animation
function reset(per){
      breakClicked = false;
      sessClicked = false; 
      totaltime = per * 60;
      countD= per * 60 * 1000;    
      count = 0;
      timeLoad(countD);
}

//Starts the counter if its is not already counting
function countStart(){
  if (countOn == false && pause==false){ 
      countOn = true;    
      //The counter starts either the Session or Break depending on whether the session switch is on or off
      //Sets the Session title and colour
      if (sessOn === false){
         totaltime = sessL * 60;
         countD=sessL * 60 * 1000;
         curr = "SESSION";
         document.getElementById("current").innerHTML= curr;
         col = 'green';          
       }
      //Sets the Break title and colour
      if (sessOn === true){
        totaltime = breakL * 60;
        countD= breakL * 60 * 1000;
        curr = "BREAK";        
        document.getElementById("current").innerHTML= curr;
        col = 'yellow';
      }
      //Sets the time in hours minutes and seconds
      timeLoad(countD);
      //Starts the time count
      counter(); 
    }
}    
    
//Animated timer    
function update(percent){
        timerSet(countD -1000);
        counting = true;
        //First half of pie timer
        var deg;    
        if(percent<(totaltime/2)){
          deg = 90 + (360*percent/totaltime);
          $('.pie').css('background-image', 'linear-gradient('+deg+'deg, transparent 50%, #2C3539 50%),linear-gradient(90deg, #2C3539 50%, transparent 50%)');
          $(".pie").css({'background-color': col, 'border-color': col});              
        //Second half of pie timer         
        }else if(percent>=(totaltime/2)){
          deg = -90 + (360*percent/totaltime);
          $('.pie').css('background-image', 'linear-gradient('+deg+'deg, transparent 50%, '+ col +' 50%),linear-gradient(90deg, #2C3539 50%, transparent 50%)');
         }
}

//The time counter
function counter(){ 
  myCounter = setInterval(function(){
   //Stops the timer if the pause button has been pressed 
   if(pause == true){
       clearTimeout(myCounter);    
   }
   //Counts if the pause button has noT been pressed
    if(pause == false){
      count+=1;
    }
    //Updates the timer animation
    update(count);
    //Events at the end of the current timer
    if(count==totaltime){
       countEnd();
    }
  }, 1000);
}

function countEnd(){
    count = 0;
    //Turns the session switch off if its on
    if(sessOn === true){       
       sessOn = false;
    }
    //Turns the session switch on if its off
    else if(sessOn === false){
        sessOn = true;
    }
    //Stops counter
    clearInterval(myCounter);
    //Turns the counter switch off for the next round
    countOn = false;
    //Turns off each period switch
    breakClicked = false;
    sessClicked = false;
    //Starts the next period
    countStart(); 
}
            
          
!
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