cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <div id = "container">
  <h1>Simple Pomodoro Clock</h1>
</div>
<div id = "container">
<h4>Pomodoro Length: </h4>
<input id = "clock" value = 25>
<h4>Break Length: </h4>
<input id = "break" value = 5>
</div>
<div id = "container">
<button id = "start">Start my clock!</button>
<div id = "continue">
</div>
</div>
<h2 id = "demo"></h2>
<div id="myProgress">
  <div id="myBar"></div>
</div>
<div id = "timeType">
</div>
            
          
!
            
              h3 {
  text-align: center;
}
h2 {
  text-align: center;
  margin-bottom: -30px;
}
#container {
  display: flex;
  justify-content: center;
}
h4 {
  margin-right: 20px;
}
input {
  margin-right: 20px;
}
button {
  margin: 20px;
}
#myProgress {
  width: 75%;
  background-color: #ddd;
  margin: auto;
}

#myBar {
  width: 0%;
  height: 30px;
  background-color: red;
}
            
          
!
            
              
$(document).ready(function(){
  var minutes;
  var seconds;
  var startMinutes;
  var startSeconds;
  var barSeconds;
  var started = false;
  var active = true;
  var width = 0.00;
  
  $("#start").click(function(){
    active = true;
    if (started == false) {
    started = true;
    $("#start").html("Pause my clock!");
    $("#continue").html("");
    startMinutes = $("#clock").val();
    startSeconds = startMinutes*60;
      barSeconds = startSeconds;
      width = 0.00;
    document.getElementById("myBar").style.backgroundColor = "red";
      document.getElementById("myBar").style.width = 0;
      $("#timeType").html("<h3>Work time!</h3>");
      $("h3").css("color", "red");
  
	 interval = setInterval(function() {
      // Time calculations for days, hours, minutes and seconds
      minutes = Math.floor(startMinutes % (60));
      seconds = Math.floor(startSeconds % (60));
    
     //Make seconds look good
    if(parseInt(seconds) < 10) {
      seconds = "0" + seconds;
    }

      // Output the result in an element with id="demo"
      document.getElementById("demo").innerHTML = minutes + ":" + seconds;
     
     //Progress bar
     if(startSeconds != barSeconds) {
     width += 100/barSeconds;
    document.getElementById("myBar").style.width = width + '%';
     }
    
      if(seconds == 0)
      {
          startMinutes = startMinutes - 1;
      }
      startSeconds = startSeconds - 1;
      if(startSeconds < 0) {
        
        if(active) {
          startMinutes = $("#break").val();
          startSeconds = startMinutes*60;
          active = false;
          width = 0.00;
    document.getElementById("myBar").style.backgroundColor = "#4CAF50";
          $("#timeType").html("<h3>Break time!</h3>");          $("h3").css("color", "#4CAF50");
          barSeconds = startSeconds;
        }
        else {
          startMinutes = $("#clock").val();
          startSeconds = startMinutes*60;
          active = true;
          width = 0.00;
    document.getElementById("myBar").style.backgroundColor = "red";
          $("#timeType").html("<h3>Work time!</h3>");
          $("h3").css("color", "red");
          barSeconds = startSeconds;
        }
      }
    
	}, 1000);
    }
    else {
      started = false;
      clearInterval(interval);
      $("#start").html("Restart my clock!");
      $("#continue").html("<button id = 'cont'>Continue my clock!</button>");
    }
  });
  $("#continue").click(function(){
    if (started == false) {
    started = true;
    $("#start").html("Pause my clock!");
    $("#continue").html("");
  
	 interval = setInterval(function() {
      // Time calculations for days, hours, minutes and seconds
      minutes = Math.floor(startMinutes % (60));
      seconds = Math.floor(startSeconds % (60));
    
     //Make seconds look good
    if(parseInt(seconds) < 10) {
      seconds = "0" + seconds;
    }

      // Output the result in an element with id="demo"
      document.getElementById("demo").innerHTML = minutes + ":" + seconds;
     //Progress bar
     width += 100/barSeconds;
    document.getElementById("myBar").style.width = width + '%';
    
      if(seconds == 0)
      {
          startMinutes = startMinutes - 1;
      }
      startSeconds = startSeconds - 1;
      if(startSeconds < 0) {
        
        if(active) {
          startMinutes = $("#break").val();
          startSeconds = startMinutes*60;
          active = false;
          width = 0.00;
          document.getElementById("myBar").style.backgroundColor = "#4CAF50";
          $("#timeType").html("<h3>Break time!</h3>");
          $("h3").css("color", "#4CAF50");
          barSeconds = startSeconds;
        }
        else {
          startMinutes = $("#clock").val();
          startSeconds = startMinutes*60;
          active = true;
          width = 0.00;
          document.getElementById("myBar").style.backgroundColor = "red";
          $("#timeType").html("<h3>Work time!</h3>");
          $("timeType").css("color", "red");
          barSeconds = startSeconds;
        }
      }
	}, 1000);
    }
    else {
      started = false;
      clearInterval(interval);
      $("#start").html("Restart my clock!");
      $("#continue").html("<button id = 'cont'>Continue my clock!</button>");
    }
  });
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console