123

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.

            
              <body>
  <div class="container-fluid text-center">
    <h1 class="text-center" id="header">
      <strong>Pomodoro Clock</strong>
    </h1>
    
    <div class="row" id="row"><div class="col-md-3 col-sm-2 col-xs-1"></div>
      <div class="col-md-3 col-sm-4 col-xs-5 block" id="left">
        <h2>BREAK LENGTH</h2>
        <div class="toggle">
          <button class="btn block minus">-</button>
          <p class="block"id="restTime">5</p>
          <button class="btn block plus">+</button>
        </div>
      </div>
      <div class="col-md-3 col-sm-4 col-xs-5 block" id="right">
        <h2>SESSION LENGTH</h2>
        <div class="toggle">
          <button class="btn block minus">-</button>
          <p class="block" id="sessTime">25</p>
          <button class="btn block plus">+</button>
        </div>
      </div>
    </div>
    <div class="circle text-center">
      <h3 id="countWindow">25:00</h3>
    </div>
    <h2 id="clockTag"><strong>IN SESSION</strong></h2>
    <div class="switch btn-group" role="group" aria-label="startStopReset">
      <button type="button" class="btn btn-success" id="start"><i class="fa fa-play" aria-hidden="true"></i></button>
      <button type="button" class="btn btn-danger" id="stop"><i class="fa fa-stop" aria-hidden="true"></i></button>
      <button type="button" class="btn btn-warning" id="reset"><i class="fa fa-repeat" aria-hidden="true"></i></button>
    </div>
    <audio controls id="myAudio">
  <source src="http://www.wavsource.com/snds_2017-05-21_1278357624936861/movies/star_wars/servant.wav" type="audio/wav">
</audio>
  </div>
</body>
            
          
!
            
              body{
  color: white;
  /* Location of the image */
  background-image: url(http://img10.deviantart.net/2174/i/2010/191/e/1/dark_weather_by_noe_me.jpg);
  
  /* Background image is centered vertically and horizontally at all times */
  background-position: center top;
  
  /* Background image doesn't tile */
  background-repeat: no-repeat;
  
  /* Background image is fixed in the viewport so that it doesn't move when 
     the content's height is greater than the image's height */
  background-attachment: fixed;
  
  /* This is what makes the background image rescale based
     on the container's size */
  background-size: cover;
  
  /* Set a background color that will be displayed
     while the background image is loading */
  background-color: #464646;
}

#header{
  margin-top: 5%;
}

h1{
  font-family: "Brush Script MT", cursive;
  font-size: 64px;
}

.block{
  display: inline-block;
  background-color: Transparent;
  color: white;
}

h2{
  font-family: helvetica;
  font-size: smaller;
  margin-top: 3%;
}

#clockTag{
  margin-top: 1%;
}

.circle{
  width:150px;
  height:150px;
  border-radius:75px;
  font-size:20px;
  color:#fff;
  line-height:100px;
  text-align:center;
  background:#5cb85c;
  margin: auto;
  display: table;
}

#countWindow {
  display: table-cell;
  vertical-align: middle;
}

#stop{
  display: none;
}

#start, #stop, #reset{
margin-top: 1%;
max-width: 60px;
min-width: 60px;
}

audio{
  display: none;
}
            
          
!
            
              $(document).ready(function(){
  var state = "session";
  var restMins = 5;
  var restSeconds = 0;
  var sessionMins = 25;
  var sessionSeconds = 0;
  var vid = document.getElementById("myAudio");
  
  //function that ammends the session and break times
  function changeTimes(button, sessionBreak){
    if (button === '-' && sessionBreak === 'SESSION LENGTH' && sessionMins>1){
      sessionMins = sessionMins-1;
    }
    else if(button === '+' && sessionBreak === 'SESSION LENGTH'){
      sessionMins = sessionMins+1;
    }
    else if(button === '-' && sessionBreak === 'BREAK LENGTH' && restMins>1){
      restMins = restMins-1; 
    }
    else if(button === '+' && sessionBreak === 'BREAK LENGTH'){
      restMins = restMins+1;
    }
    return restMins, restSeconds, sessionMins, sessionSeconds;
  }
  
  //play audio function
  function playAud() { 
    vid.play(); 
} 
  
  //check whether the time has counted down to '0:00'. Change state if so.
  function switchTimes(mins, seconds){
    if (state === 'session' && mins === 0 && seconds === 0){
      state = 'rest';
      $('body').css('background-image', 'url(http://onehdwallpaper.com/wp-content/uploads/2015/07/Beautiful-Scenery-HD-Wallpapers-Pictures-8.jpg)');
      $('#clockTag').text('TAKE A BREAK');
      sessionMins = parseInt($('#sessTime').text());
      sessionSeconds = 0;
      playAud();
    }
    else if (state ==='rest' && mins === 0 && seconds === 0){
      state = 'session';
      $('body').css('background-image', 'url(http://img10.deviantart.net/2174/i/2010/191/e/1/dark_weather_by_noe_me.jpg)');
      $('#clockTag').text('IN SESSION');
      restMins = parseInt($('#restTime').text());
      restSeconds = 0;
      playAud();
    }
    return state, sessionMins, sessionSeconds, restMins, restSeconds;
  }
  
  //check the lenght and add '0' to seconds and mins if needed
  function checkNumLength(mins, seconds){
   switchTimes(mins, seconds);
    
    switch(seconds.toString().length){
     case 1:
          seconds = '0' + seconds
          $('#countWindow').text(mins + ':' + (seconds));
          console.log(mins + ':' + seconds);
          break;   
     
     case 2:
          $('#countWindow').text(mins + ':' + seconds);
          console.log(mins + ':' + seconds);
          break;
                                    }
    switch(mins.toString().length){
      case 1:
          $('#countWindow').text('0' + mins + ':' + seconds);
          break;  
      
      case 2:
          $('#countWindow').text(mins + ':' + seconds);
          break;
                                 }
    return mins, seconds;
  }
  
  //This function is called when the start button is clicked. It counts down to zero (in progress). Need to add switch function somewhere (to switch to from session to rest – and vice-versa – when the time reaches 0).
  function myTimeoutFunction(){
    
    //Check whether the countdown should be session clock or rest clock
    if (state === 'session' && sessionSeconds > 0){
     sessionSeconds = sessionSeconds-1;
     var seconds = sessionSeconds;
     var mins = sessionMins;
    }
    
    else if(state === 'session' && sessionSeconds === 0){
      sessionMins = sessionMins-1;
      sessionSeconds = 59;
      mins = sessionMins;
      seconds = sessionSeconds;
    }
    
    else if(state === 'rest' && restSeconds > 0){
      restSeconds = restSeconds-1;
      seconds = restSeconds;
      mins = restMins;
    }
    
    else if(state === 'rest' && restSeconds === 0){
      restMins = restMins-1;
      restSeconds = 59;
      mins = restMins;
      seconds = restSeconds;
    }
    
    checkNumLength(mins, seconds)
}

  //begin clock countdown
  function countDown(){
   
    //If stop is pressed, run this function to interrupt the countdown
    function stopTime(){
    window.clearInterval(timerId);
  }
    //reset the time when the reset button is pressed
    function resetTime(){
      state = 'session';
      sessionMins = parseInt($('#sessTime').text());
      sessionSeconds = 0;
      checkNumLength(sessionMins, sessionSeconds);
    }
    //This will initial the repeated function for countdown (every 1000ms)
    var timerId = window.setInterval(myTimeoutFunction, 1000);
    $('.switch').on('click', '#stop', function(){
    $('#stop').hide();
    $('#start').show();
    stopTime();
  });
    $('.switch').on('click', '#reset', function(){
    $('#stop').hide();
    $('#start').show();
    stopTime();
    resetTime();
    });
  }
  
  
  //Call 'time' function when the time toggle buttons are pressed
  $('.toggle').on('click', '.btn', function(){
    changeTimes($(this).html(), $(this).parent('div').prev('h2').text());
    $('#left').find('p').text(restMins);
    $('#right').find('p').text(sessionMins);
    if (state==='session'){
      checkNumLength(sessionMins, sessionSeconds);
   }
    else if (state==='rest'){
      checkNumLength(restMins, restSeconds);
    }
  });
  
  //Start button clicked to start countdown
  $('.switch').on('click', '#start', function(){
    $('#start').hide();
    $('#stop').show();
    countDown();
  });
});
            
          
!
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