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.

            
              <div class="container">
  <div class="row">
    <div class="col-xs-12">
    <header>Pomodoro Clock</header>
  <h2>BREAK LENGTH
  
    </br><span class="clickable button hvr-bounce-in">-</span><span class="time" id="rest">5</span><span class="clickable button hvr-bounce-in">+</span>
</h2>
  <h2>SESSION LENGTH

</br><span class="clickable button hvr-bounce-in">-</span><span class="time" id="work">25</span><span class="clickable button hvr-bounce-in">+</span>

  </h2>

<h1><span id="title">Session</span></br><span id="timer">25</span></h1>

      <span id="start" class="clickable fa fa-play hvr-bounce-in"></span>

      <span id="reset" class="clickable fa fa-repeat hvr-bounce-in"></span>
    <p>To start the countdown click start!</p>
    <p>Pause and unpause by tapping the start button!</p>
    <p>To reset the clock, click the reset button!</p>    
</div>
</div>
</div>
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Montserrat|Pacifico');

$padding: 30px;
$font-size: 25px;

body {
  font-family: Montserrat;
  margin-top: 35px;
  text-align: center;
  font-size: $font-size;
  background: url("https://hd.unsplash.com/photo-1444952483853-7c36e902e722") no-repeat fixed center;
  background-size: cover;
  color: white;
  text-shadow: black 0.3em 0.3em 0.3em;
  header {
    font-family: Pacifico;
    font-size: $font-size + 20;
  }
  h2 {
    padding: $padding;
    display: inline-block;
  }
  .clickable {
    cursor: pointer;
    padding: $padding - 10;
  }
}
            
          
!
            
              var audio = $("#buzzer")[0],
  workTime = parseInt($("#work").text()),
  restTime = parseInt($("#rest").text()),
  workTimeInSec = workTime *= 60,
  restTimeInSec = restTime *= 60,
  playing = false,
  toWork = true,
  firstPeriod,
  secondPeriod;

//Increment and decrement buttons
$(".button").click(function() {

  if (playing == false) {

    var value = parseInt($(this).parent().find('.time').text());

    if ($(this).text() === "+") { // If it's a plus sign, increment the value

      $(this).parent().find(".time").text(value + 1);

    } else { // If it's a plus sign, decrement the value
      // Don't allow decrementing below one
      if (value > 1) {
        $(this).parent().find(".time").text(value - 1);

      } else {
        // Set it to one
        $(this).parent().find(".time").text("1");

      }
    }

    workTime = parseInt($("#work").text());
    restTime = parseInt($("#rest").text());
    workTimeInSec = workTime *= 60;
    restTimeInSec = restTime *= 60;
  }

});

$('#start').click(function() {
  // if the play button's value is 'play', call the play function
  // otherwise call the pause function

  if (playing === false) {

    $("#start").attr('class', "clickable fa fa-pause hvr-bounce-in");
    if (toWork) {
      $("#title").text('Session');

      firstPeriod = setInterval(work_int, 1000);

    } else {

      secondPeriod = setInterval(rest_int, 1000);
    }
    playing = true;
  } else {

    $("#start").attr('class', "clickable fa fa-play hvr-bounce-in");
    if (toWork) {

      clearInterval(firstPeriod);
    } else {

      clearInterval(secondPeriod);
    }
    playing = false;
  }

});

function countDown(val) {
  if (val % 60 >= 10) {
    $("#timer").html(Math.floor(val / 60) + ":" + val % 60);
  } else {
    $("#timer").html(Math.floor(val / 60) + ":" + "0" + val % 60);
  }
}

function work_int() {
  workTimeInSec -= 1;
  countDown(workTimeInSec);
  if (workTimeInSec === 0) {
    audio.play();
    clearInterval(firstPeriod);
    toWork = false;
    secondPeriod = setInterval(rest_int, 1000);
    $('#title').text('Break');
  }
}

function rest_int() {

  restTimeInSec -= 1;
  countDown(restTimeInSec);
  if (restTimeInSec === 0) {
    audio.play();
    clearInterval(secondPeriod);

    $("#start").attr('class', "clickable fa fa-play hvr-bounce-in");

    workTime = parseInt($("#work").text());
    restTime = parseInt($("#rest").text());
    workTimeInSec = workTime *= 60;
    restTimeInSec = restTime *= 60;
    counting = false;
    toWork = true;
  }
}

$("#reset").click(function() {
  clearInterval(firstPeriod || secondPeriod);
  $("#rest").html(5);
  $("#work").html(25);
  workTime = parseInt($("#work").text());
  restTime = parseInt($("#rest").text());
  workTimeInSec = workTime *= 60;
  restTimeInSec = restTime *= 60;
  $("#start").attr('class', "clickable fa fa-play hvr-bounce-in");
  counting = false;

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