css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

            
              <!--
-------READ ME----------
#Hello!
#You can pause and resume the timer
#by clicking on it. You can also
#increase and decrease your timer
#by clicking on the arrows next to 
#the break duration and work duration
#numbers. If you would like to reset the clock, pause the timer and change the value of the work duration number.
------------------------
-->
<audio id="audio1" preload="auto" src="https://resources.schoolscience.co.uk/CDA/CD/files/sound/decorativelamp.mp3"></audio>
<div class="container">
  <div class="row">
    <div class="text-center clock">
      <h3 id="title">Pomodoro Clock</h3>
      <div class="wrapper">
        <div class="row">
          <button style="background-color: transparent; border-color: transparent; outline: 0;" id="arrows-left" class="col-xs-4 text-left">&#10094;</button>
          <button style="background-color: transparent; border-color: transparent; outline: 0;" id="arrows-right" class="col-xs-4 text-right">&#10094;</button>
        </div>
        <div class="times row">
          <p id="break-num" class="col-xs-4 text-left"></p>
          <button style="background-color: transparent; border-color: transparent; outline: 0;" id="timer" class="col-xs-4 text-center"></button>
          <p id="work-num" class="col-xs-4 text-right"></p>
        </div>
        <div class="arrow-bottom row">
          <button style="background-color: transparent; border-color: transparent; outline: 0;" id="arrows-left-btm" class="col-xs-4 text-left">&#10094;</button>
          <button style="background-color: transparent; border-color: transparent; outline: 0;" id="arrows-right-btm" class="col-xs-4 text-right">&#10094;</button>
        </div>
      </div>
    </div>
  </div>
</div>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Pacifico);
@import url(https://fonts.googleapis.com/css?family=Roboto);
body {
  background: #ff6666;
}

.clock {
  width: 200px;
  margin: 100px auto;
  border: solid 5px #f08080;
  border-radius: 50%;
  padding: 70px;
  padding-top: 40px;
  padding-bottom: 50px;
  box-sizing: content-box;
}

#title {
  font-family: Pacifico;
  margin-bottom: 60px;
}

.wrapper {
  width: 200px;
  height: 130px;
  margin: 0 auto;
}

#arrows-left {
  font-size: 30px;
  transform: rotate(90deg);
  margin-left: -18px;
  margin-bottom: -22px;
}

#arrows-right {
  font-size: 30px;
  transform: rotate(90deg);
  float: right;
  margin-right: -12px;
  margin-top: -28px;
}

#arrows-left-btm {
  font-size: 30px;
  transform: rotate(-90deg);
  float: left;
  margin-left: -18px;
  margin-top: -25px;
}

#arrows-right-btm {
  font-size: 30px;
  transform: rotate(-90deg);
  float: right;
  margin-right: -12px;
  margin-top: 3px;
}

#break-num {
  margin-left: -5px;
  font-family: Roboto;
  font-size: 20px;
}

#work-num {
  margin-left: 5px;
  font-family: Roboto;
  font-size: 20px;
}

#timer {
  font-family: Roboto;
  font-size: 20px;
}
            
          
!
            
              var breakNum = 5;
var workNum = 25;
var breakHappen = false;
var pause = false;
var minutes,
  seconds,
  interval;
var doubleDigit = function(num) {
  num = String(num);
  if (num.length === 1) {
    return "0" + num;
  } else {
    return num;
  }
}
var myAudio = document.getElementById("audio1");
myAudio.addEventListener("load", function(){
  this.Play();
}, true)

$(function() {
  $("#break-num").html(doubleDigit(breakNum));
  $("#work-num").html(doubleDigit(workNum));
  $("#timer").html(doubleDigit(workNum) + ":00")
    //assign button functionality
  $("button").on("click", function() {
    if (this.id === "arrows-left") {
      breakNum++;
      $("#break-num").html(doubleDigit(breakNum));
    } else if (this.id === "arrows-left-btm") {
      breakNum--;
      $("#break-num").html(doubleDigit(breakNum));
    } else if (this.id === "arrows-right") {
      workNum++;
      $("#work-num").html(doubleDigit(workNum));
      $("#timer").html(doubleDigit(workNum) + ":00");
    } else if (this.id === "arrows-right-btm")  {
      workNum--;
      $("#work-num").html(doubleDigit(workNum));
      $("#timer").html(doubleDigit(workNum) + ":00");
    }
  });
  //assign timer count-down functionality
  $("#timer").on("click", function() {
    if (pause === false) {
      pause = true;
      if ($("#timer").html().substr(0, 2) == workNum) {
        minutes = workNum;
        seconds = 0;
      }

      interval = setInterval(function() {
        //new minute after seconds reach 0
        if (seconds === 0) {
          minutes--;
          seconds = 59;
        } else {
          seconds--;
        }
        $("#timer").html(doubleDigit(minutes) + ":" + doubleDigit(seconds));
        //when countdown ends
        if (minutes === 0 && seconds === 0 && breakHappen === false) {
          //adds breaktime afte countdown
          myAudio.play();
          minutes = breakNum;
          $("#title").html("Break Time!");
          breakHappen = true;
          //ends timer after breakTime
          //handles negative input
        } else if (minutes < 1 && seconds < 1 && breakHappen === true) {
          minutes = workNum;
          seconds = 0;
          breakHappen = false;
          $("#title").html("Pomodoro Clock");
          myAudio.play();
        }
      }, 1000);
    } else if (pause === true) {
      pause = false;
      minutes = $("#timer").html().substr(0, 2);
      seconds = $("#timer").html().substr(3);
      clearInterval(interval);

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

Console