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 id='set-length'>
    <label id='break-length' for='break-length'>break Length</label> 
    <button class='plus-b'>+</button>
    <span class='number-b'>1</span>
    <button class='minus-b'>-</button>
    <label id='session' for='session-length'>session Length</label>
    <button class='plus'>+</button>
    <span class='number'>1</span>
    <button class='minus'>-</button>
  </div>
  <div id='time-container'>
    <h2 id='timeName'>Session</h2>
    <time id='time'>1</time> 
  </div>
  <button id='start' onclick='sessionCountdown.start(Number(sessionNumber.textContent))'>start</button>
 <button id='pause' onclick='sessionCountdown.paused()'>pause</button>
  <button id='resume' onclick='sessionCountdown.resumed()'>resume</button>
</div>
            
          
!
            
              .container{
  max-width: 500px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 500px;
  grid-template-rows: 90px 120px;
  justify-items: center;
  background-color: red;
}

#time-container{
  display:grid;
  grid-template-columns: 500px;
  justify-items: center;
  grid-template-rows: 70px auto;
}

#set-length{
  display:grid;
  grid-template-rows: 25px 25px;
  grid-template-columns: repeat(6, 83.3px);
  justify-items:center;
  grid-template-areas: 'break break break session session session'
    'plus-b number-b minus-b plus number minus'
}

#break-length{
  grid-area: break;
}

#session{
  grid-area:session;
}

.plus-b{
  grid-area:plus-b;
}

.number-b{
  grid-area:number-b;
}

.minus-b{
  grid-area: minus-b;
}

.plus{
  grid-area:plus;
}

.number{
  grid-area: number;
}

.minus{
  grid-area:minus;
}


/** session buttons **/

#pause{
  display: none;
}

#resume{
  display:none;
}
            
          
!
            
              
let session; 
let breakStart;

const breakPlus = document.querySelector('.plus-b');
 
const time = document.querySelector('#time');

const breakMinus = document.querySelector('.minus-b');

const breakNumber = document.querySelector('.number-b');
 
const sessionPlus = document.querySelector('.plus');

const sessionNumber = document.querySelector('.number');

const sessionMinus = document.querySelector('.minus');
  
let timeName = document.querySelector('#timeName');

/** session buttons **/ 

const startButton = document.querySelector('#start');

const pause = document.querySelector('#pause');

const resume = document.querySelector('#resume');

sessionPlus.addEventListener('click', plusSession);

sessionMinus.addEventListener('click', minusSession); 

breakMinus.addEventListener('click', MinusBreak);

breakPlus.addEventListener('click', plusBreak);

function plusBreak(){
  let plus = Number(breakNumber.textContent);
    plus++;
    breakNumber.textContent = plus;
  
}

function MinusBreak(){
  if(Number(breakNumber.textContent > 1)){
   let minus = Number(breakNumber.textContent);
  minus--;
  breakNumber.textContent = minus;
  }
}

function plusSession(){ 
  let plusOne = Number(sessionNumber.innerHTML);
  plusOne++;
  [sessionNumber, time].forEach(elem => elem.textContent = plusOne);
  if (session === true){
    clearInterval(sessionInterval);
    sessionCountdown.start(Number(sessionNumber.textContent));
  } 
}

function minusSession(){
  let minusOne = Number(sessionNumber.innerHTML);
  minusOne--;
  if(minusOne === 0){ 
    return;
    sessionTime();
  } 
  [sessionNumber, time].forEach(elem => elem.textContent = minusOne);
  if (session === true){
    clearInterval(sessionInterval);
    sessionCountdown.start(Number(sessionNumber.textContent));
  }
}  

/** functions for count down **/

 let timer = function(){
   
    this.start = function(sessionMinutes){
      
      session = true;  
      startButton.style.display = 'none';
      
      pause.style.display = 'unset'; 
    
      let timeMinutes = 60 * sessionMinutes;
       let breaks = Number(breakNumber.textContent) * 60;
        
      function countSession(){
        if(session === true){
         // Time calculations for minutes and seconds
        
        let  minutes = parseInt(timeMinutes / 60, 10);
        let seconds = parseInt(timeMinutes % 60, 10);
     
        // Time calculations for minutes and seconds

    minutes = minutes < 10 ? "0" + minutes : minutes; 
    seconds = seconds < 10 ? "0" + seconds : seconds;
 
        time.textContent = minutes + ':' + seconds; 
        
           //if over do something
          timeMinutes--;
        if (timeMinutes < 0){
            clearInterval(sessionInterval);
            timeName.textContent = 'break';
            time.textContent = 'done';
             breakStart = true
         }  
        }  
       } 
      
      function countBreak(){
        if(breakStart === true){
         // Time calculations for minutes and seconds

        let  minutes = parseInt(breaks / 60, 10);
        let seconds = parseInt(breaks % 60, 10);
     
        // Time calculations for minutes and seconds

    minutes = minutes < 10 ? "0" + minutes : minutes; 
    seconds = seconds < 10 ? "0" + seconds : seconds;
 
        time.textContent = minutes + ':' + seconds; 
           //if over do something
          breaks--;
        if (breaks < 0){
            clearInterval(breaksInterval);
          breakStart = false;
            timeName.textContent = 'restart?';
            time.textContent = 'done';
         }    
        }    
       } 
      breaksInterval = setInterval(countBreak, 1000)
     sessionInterval = setInterval(countSession, 1000);
    }   
       
    //paused 

    this.paused = function (){
        pause.style.display='none';
        resume.style.display='unset';
        session = false;
      console.log('sdfsdf');
      }
    
    //resume

    this.resumed = function (){
        resume.style.display='none';
        pause.style.display='unset';
        session = true;
    } 
} 
   
let sessionCountdown = new timer();
 
            
          
!
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