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">
  <h1>FreeCodeCamp<h1/>
  <h2>Pomodoro Clock</h2>
    
  
   <div class="control">
 <div class="changeTime">
   <p class="breakLength">Break Time</p>
  <div class="breakItems">
    <span class="btn btn-primary" id="breakMinus">-</span>
   <span><p class="breakStart" id="breakControl">5</p></span>
    <span class="btn btn-primary" id="breakPlus">+</span>
     </div>
     </div>

    <div class="changeTime">
      <p>Session Time</p>
      <div class="sessionItems">
    <span class="btn btn-primary" id= "sessionMinus">-</span>
    <span ><p class="sessionClock">25</p></span>
      <span class="btn btn-primary" id= "sessionPlus">+</span>
      
  </div>
    </div>
</div>
  
  <div class="timer">
    <div class="timerContent">
      <h3 class="breakTime">Break Time</h3>  
      <h3 id="sessionTime">Session</h3>
    <h2 class="sessionClock">25</h2>
  <span><a href="#" class="btn btn-primary" id="start">Start</a><span>
    </div>
</div>
      <a href="#" class="btn btn-primary" id="reset">reset</a> 



  <!--  <div class="session">
      <h3>Session Length</h3>
      <a href="#" class="btn btn-primary sessionMinus">-</a>
      <h4 class="sessionClock">5</h4>
      <a href="#" class="btn btn-primary sessionPlus">+</a>
  
    </div> -->
            
          
!
            
              body {
  text-align: center;
}
.container{
 
 text-align: center;
}
.changeTime{
  display: inline-block;
  padding: 20px;
}

.breakItems {
  display: flex;
  justify-content: center;
 
}

.sessionItems {
  display: flex;
  justify-content: center;
}
p{
  font-size: 20px;
}
.timer {
  display: flex;
  justify-content:center;
  align-content: center;
  
}
.timerContent{
  border-radius: 50%;
  border: 5px solid #ffe4e1;
  width: 250px;
  height: 250px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-content: center;
  margin-top: 20px;
  
}
.breakControl h2{
  font-size: 30px;
}



            
          
!
            
              //https://www.soundjay.com/button/beep-027.mp3

$(document).ready(function() {
  var audio = new Audio(
    "https://notificationsounds.com/soundfiles/05f971b5ec196b8c65b75d2ef8267331/file-sounds-792-the-little-dwarf.mp3");
  audio.volume=0.5;
  //Turn string value in the html into integer
  var sessionCount=parseInt($(".sessionClock").html())
  var session = parseInt($(".sessionClock").html());
  var breakTime = parseInt($(".breakStart").html());
  var timeLeft=session;
  var paused = true;
  var counter;
  
/*   function convert(s){
    var min=Math.floor(s/60); 
    var sec=s%60;
    return min + ":" + sec;
  }
   */
  
  
  $(".breakTime").hide();

  //Update controls for Break Time
  $("#breakMinus").click(function() {
    //Lower limit is 1 min
    if (breakTime > 1) {
      breakTime--;
      $(".breakStart").html(breakTime);
      /* event.preventDefault(); */
    } // end of breakMinus if
  }); //breakMinus function
  $("#breakPlus").click(function() {
    breakTime++;
    $(".breakStart").html(breakTime);
     event.preventDefault(); 
  }); //end breakPlus function
  
  //Update controls for Session Time
  $("#sessionMinus").click(function() {
    //Lower limit is 1 min
    if (session > 1) {
      session--;
      $(".sessionClock").html(session);
      event.preventDefault(); 
    } //end if sessionMinus
  }); //end sessionMinus function
  
  $("#sessionPlus").click(function() {
    session++;
    $(".sessionClock").html(session);
     event.preventDefault(); 
  }); // end sessionPlus Function

  //Start button tiggers timer.
  $("#start").click(function() {
    event.preventDefault(); 
   $(".changeTime").hide();
    // toggle between start and stop.
  
    clearInterval(counter);
    //
    if (paused) {
      
      clearInterval(counter);
     counter = setInterval(timer, 1000);
      $(this).text("stop").addClass("stop_button");
      paused = false;
    } else {
      $("#start").text("Start").removeClass("stop_button");
      clearInterval(counter);
      paused = true;
    }
  }); 

  //Timer count downs.
 counter=setInterval(timer,1000);
  function timer() {
    $("#start");
    
    session-=1;
    if (session === 0) {
      clearInterval(counter);
      audio.play();
   
      var startBreak = setInterval(breakTimer, 1000);
      $(".breakTime").show();
      $("#sessionTime").hide();
    }
   
//$(".sessionTimer").html(session);
    
    // turns time into minutes and seconds
     
      if(session% 60 >=10){
        
      $(".sessionClock").html(Math.floor(session/60) + ":" + session % 60);
    } else{
      $(".sessionClock").html(Math.floor(session/60) + ":" + "0" + session % 60);
    } 
     
    //Start of the break time.
   
    function breakTimer() {
      breakTime -= 1;
       $(".stop_button").click(function() {
    clearInterval(startBreak);
  }); 
      if (breakTimer === 0) {
        clearInterval(counter);
        audio.play();
      }
     
     
       if(breakTime % 60 >=10){
      $(".sessionTimer").html(Math.floor(breakTime/60) + ":" + breakTime % 60);
    } else{
      $(".sessionTimer").html(Math.floor(breakTime/60) + ":" + "0" + breakTime % 60);
    }  
    }
  }

  $(".stop_button").click(function() {
    clearInterval(counter);
  });
   
$("#reset").click(function(){
    clearTimeout(counter);
        event.preventDefault();
  $(".changeTime").show();
  $('.breakTime').hide();
  $("#sessionTime").show();
  } );   
 /*  $("#reset").click(function(){
     session=25;
     $(".sessionTimer").html(session);
     $(".breakTime").hide();
     $("#sessionTime").show();
   }); */
});


//}

/*  if( $("#reset").click(function(){
     session=25;
     $(".sessionTimer").html(session);
     $(".breakTime").hide();
     $("#sessionTime").show();
   }));  */

/*     $("#breakMinus").click(function(){
   
      if(count>0){
        count--;
        $(".breakStart").html(count);
}
  event.preventDefault();
  }); */
//    $(".sessionPlus").click(function(){

//      session++;
//     $(".sessionClock").html(session);
//     console.log(session);
//   });
//     $(".sessionMinus").click(function(){

//       if(session>=0){
//         session--;
//         $(".sessionClock").html(session);
// }

            
          
!
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