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-fluid">
  <h1>Let's get Productive!</h1>
  <div id="time_set">
    <div id="break_time">Break Length
      <div id="minute_change">
        <button class="time_modify" id="minus_break" style="float:left; width:10%"> - </button>
        <div id="initial_break" style="float: left; width: 10%"> </div>
        <button class="time_modify" id="plus_break" style="float:left; width: 10%"> + </button>


      </div>

    </div>
    <div id="work_time"> Session Length
      <div id="minute_change">
        <button class="time_modify" id="minus_work" style="float:left; width:10%"> - </button>
        <div id="initial_work" style="float: left; width: 10%"> </div>

        <button class="time_modify" id="plus_work" style="float:left; width: 10%"> + </button>


      </div>

    </div>
  </div>
  <div id="clock">
    <button class="timer"> 
			<span id = "session" style = "margin: auto;">Start Session</span>
			<br>
			<br>
			<span id = "minute">  </span>


		</button>
  </div>
  <button class="reset">Reset</button>
</div>
            
          
!
            
              body {
  background-color: #74D925;
  font-family: helvetica;
}

h1 {
  text-align: center;
  font-size: 50px;
}

#break_time {
  float: left;
  width: 50%;
  text-align: center;
  font-size: 50px;
}

#work_time {
  float: right;
  width: 50%;
  text-align: center;
  font-size: 50px;
}

#minute_change {
  width: 50%;
  margin-left: 42%;
}

.time_modify {
  background: none;
  border: none;
  height: 50px;
  width: 100px;
  font-size: 20px;
  cursor:pointer;
  outline:none;
}

#clock {
  text-align: center;
}

.timer {
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background: none;
  border: solid;
  margin-top: 10px;
  font-size: 50px;
  cursor:pointer;
  outline:none;
}

.reset {
  background: none;
  width: auto;
  font-size: 40px;
  outline: none;
  border: 0;
  margin-left: 47%;
  margin-top: 20px;
  cursor:pointer;
  outline:none;
}
            
          
!
            
              $(document).ready(function() {
  var initial_break = 5;
  var initial_work = 25;
  //Store minutes in seperate value so timer can reset to original value when timer fully elapsed
  var break_minute = 5;
  var work_minute = 25;
  var seconds = 0;
  //Stops the timer
  var paused = false;
  //Switch back and forth from break time
  var rest_time = false;
  //Check session status so user can't modify time mid-session.
  var session = false;
  var audio = new Audio("http://www.mediacollege.com/downloads/sound-effects/city/factorywhistle-01.mp3");
  //Will store setInterval function
  var countdown;
  $("#initial_break").text(initial_break);
  $("#initial_work").text(initial_work);
  $("#session").text("Start Session");
  $("#minute").text(initial_work);

  $("#minus_break").on("click", function() {
    if (initial_break > 1 && session === false) {
      initial_break--;
      break_minute = initial_break;
      $("#initial_break").text(initial_break);
    }
  });

  $("#plus_break").on("click", function() {
    if (initial_break < 15 && session === false) {
      initial_break++;
      break_minute = initial_break;
      $("#initial_break").text(initial_break);

    }
  });

  $("#minus_work").on("click", function() {
    if (initial_work > 1 && session === false) {
      initial_work--;
      work_minute = initial_work;
      $("#minute").text(initial_work);
      $("#initial_work").text(initial_work);

    }
  });

  $("#plus_work").on("click", function() {
    if (initial_work < 40 && session === false) {
      initial_work++;
      work_minute = initial_work;
      $("#minute").text(initial_work);
      $("#initial_work").text(initial_work);
    }
  });

  $(".timer").on("click", function() {
    session = true;
    //If session is not paused, proceed with countdown
    if (paused === false) {
      countdown = setInterval(function() {
        //Session time
        if (rest_time === false) {
          if (seconds < 10) {
            seconds = '0' + seconds;
          }
          $("#session").text("Pause Session");
          $("#minute").text(work_minute + ":" + seconds);
          seconds--;

          if (work_minute === 0 && seconds === -1) {
            rest_time = true;
            work_minute = initial_work;
            seconds = 0;
            $("html body").animate({
              backgroundColor: "#03FBCA"
            });
            audio.play();
          } else if (work_minute > -1 && seconds === -1) {
            seconds = 59;
            work_minute--;

          }

        }
        //Break time
        else if (rest_time === true) {
          if (seconds < 10) {
            seconds = '0' + seconds;
          }
          $("#session").text("Pause Break");
          $("#minute").text(break_minute + ":" + seconds);
          seconds--;

          if (break_minute === 0 && seconds === -1) {
            rest_time = false;
            break_minute = initial_break;
            seconds = 0;
            $("html body").animate({
              backgroundColor: "#74D925"
            });
            audio.play();

          } else if (break_minute > -1 && seconds === -1) {
            seconds = 59;
            break_minute--;
          }

        }

      }, 1000);
    }
    //When user pauses session
    else {
      $("#session").text("Resume");
      clearInterval(countdown);

    }
    //Paused value changes with each click
    paused = !paused;

  });

  $(".reset").on("click", function() {
    clearInterval(countdown);
    $("#initial_break").text(initial_break);
    $("#initial_work").text(initial_work);
    $("#session").text("Start Session");
    $("#minute").text(initial_work);
    $("html body").animate({
      backgroundColor: "#74D925"
    });
    seconds = 0;
    paused = false;
    rest_time = false;
    session = 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