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.

            
              <body>
        
        <div id="about-overlay" onclick="overlayOff()">
        <div class="about-content">
        <p>From: https://en.wikipedia.org/wiki/Pomodoro_Technique</p>
            <p><b>The Pomodoro Technique</b> is a time management method developed by Francesco Cirillo in the late 1980s.The technique uses a timer to break down work into intervals, traditionally 25 minutes in length, separated by short breaks. These intervals are named pomodoros, the plural in English of the Italian word pomodoro (tomato), after the tomato-shaped kitchen timer that Cirillo used as a university student.</p><br>
<p>
The technique has been widely popularized by dozens of apps and websites providing timers and instructions. Closely related to concepts such as timeboxing and iterative and incremental development used in software design, the method has been adopted in pair programming contexts.
        </p>
            </div></div>
    
<div class="container">
    <h1>POMODORO TIMER</h1>
    <h5 id="about-link" onclick="overlayOn()">What is it?</h5>
    
    
    
<div class="row1">
    
        <div class="control1" >Work
            <h3 class="duration"><span class="duration signs" id="dur-work-down">- </span>&nbsp<span class="duration" id="dur-work"></span>&nbsp<span class="duration signs" id="dur-work-up"> +</span></h3></div>
    <div class="control1">Break
        
        <h3 class="duration"><span class="duration signs" id="dur-break-down">- </span>&nbsp<span class="duration" id="dur-break">5</span>&nbsp<span class="duration signs" id="dur-break-up"> +</span></h3></div>
        </div>
        
      <div class="timer-container">
    <div class="timer">
            </div>
    <div class="message"></i></div>
          <div class="progress-container">
              <div class="progress-bar">bla
              </div>
          </div>
    </div>
    <div id="reset">RESET</div>
        </div>
    
    </div>
    <audio id="beepSound">
  <source src="Censor%20Beep-SoundBible.com-250233510.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>
    <script src="pomodoro2.js"></script>
	</body>
            
          
!
            
              *{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: Sans-serif;
    font-size: 0;
}

body{
    background-color: #5a4105;
    background-image: url(https://i0.wp.com/karinawidyani.files.wordpress.com/2017/12/books3.png);
    background-repeat: no-repeat;
    background-size: cover;
    background-attachment: fixed;
}

.container{
    width: 500px;
    text-align: center;
    margin: 30px auto;
}

h1{
    font-size: 35px;
    font-family: 'Bungee', cursive;
    color: #ebc185;
    letter-spacing: 3px;
    margin-bottom: 0;
    text-align: center;
}

h5{
    font-size: 15px;
    color: white;
    margin-top: -15px;
    margin-bottom: 20px;
    cursor: pointer;
    text-align: center;
}

h5:hover{
    color: #edd3af;
}

#about-overlay{
    display: none;
    position: absolute;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.4);;
    padding: 100px;
    z-index: 1;
}

.about-content{
    background-color: #edd3af;
    width: 400px;
    height: 370px;
    z-index: 2;
    margin: 0 auto;
    padding: 20px;
    border-radius: 5px;
}

#about-overlay > .about-content > p{
    font-size: 15px;
    color: black;
    text-align: left;
    padding: 5px;
}

#about-overlay > .about-content > p > b{
    font-size: 15px;
    font-weight: bold;

}



.control1{
    display: inline-block;
    width: 150px;
    height: 70px;
    color: white;
    border: 1px solid #ebc185;
    font-size: 15px;
    text-align: center;
    margin: 10px;
    padding: 10px;
    border-radius: 5px;
}

.duration{
    font-size: 25px;
    
}

.signs{
    cursor: pointer;
}

.timer-container{
    position: relative;
    width: 320px;
    height: 200px;
    border: 3px solid #ebc185;
    border-radius: 5px;
    text-align: center;
    margin: 10px auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    
}

.timer-container > .timer{
    color: white;
    font-size: 45px;
}

.timer-container > .message{
    color: white;
    font-size: 20px;
    margin-top: 15px;
    
}

.progress-container{
    position: absolute;
    left: 8px;
    top: 170px;
    width: 300px;
    height: 20px;
    border: 1px solid #ebc185;
    margin: 0 auto;
}

.progress-bar{
    width: 0;
    height: 18px;
    background-color: #ebc185;
}

#reset{
    margin: 20px auto 0 auto;
    width: 100px;
    height: 30px;
    line-height: 30px;
    vertical-align: middle;
    color: black;
    font-size: 15px;
    font-weight: bold;
    background-color: #ebc185; 
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

#reset:hover{
  background-color:#edd3af;
}

#image-credit{
    margin-top: 12px;
    color: white;
    font-size: 11px;
    opacity: 0.5;
}

a{
 font-size: 11px;   
    color: white;
    text-decoration: none;
}

/*=====MEDIA QUERIES=====*/

@media screen and (max-width : 320px){
  .container{
    width:70%;
    margin: 10px auto;
  }
  
    .control1{
        width: 170px;
    }
    
  .timer-container{
    width: 200px;
  }
  
  .progress-container{
    width: 93%;
  }
    
    h1{
    font-size: 25px;
    letter-spacing: 1px;
    }
    
    
    #about-overlay{
    display: none;
    position: absolute;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.4);;
    padding: 90px 5px;
    z-index: 1;
}

    .about-content{
    background-color: #edd3af;
    width: 100%;
    padding: 30px 10px;
    z-index: 2;

    border-radius: 5px;
    }
    
    #about-overlay > .about-content > p {
    font-size: 12px;
    }
    
    #about-overlay > .about-content > p > b{
    font-size: 12px;
    font-weight: bold;
    }
}
            
          
!
            
              var minWork = 25; 
var minBreak = 5; 
var timerOn; 
var seconds;
var progressBar;
var timer;
var paused;
var activity;
var width;
var pausedTime, pausedMinute, pausedSecond, timeLeft, barIncrement;
var UITimer = document.querySelector(".timer");
var UIMessage = document.querySelector(".message");
var UIBar = document.querySelector(".progress-bar");
//var sound = document.getElementById("beepSound");

//DOM Strings;;
durWork = "dur-work";
durBreak = "dur-break";

//EVENT LISTENERS
document.getElementById("dur-work-down").addEventListener("click", function(){
   
    if (minWork > 1){
        minWork--
    }
    
    document.getElementById(durWork).textContent = minWork;
    UITimer.textContent = minWork + ":00";
    
});

document.getElementById("dur-work-up").addEventListener("click", function(){
   
    minWork++;
    document.getElementById(durWork).textContent = minWork;
    UITimer.textContent = minWork + ":00";
});

document.getElementById("dur-break-down").addEventListener("click", function(){
    if (minBreak > 1){
        minBreak--;
    }
    
    document.getElementById(durBreak).textContent = minBreak;
    
});

document.getElementById("dur-break-up").addEventListener("click", function(){
    minBreak++;
    document.getElementById(durBreak).textContent = minBreak;
});
    
document.querySelector(".timer-container").addEventListener("click", playTimer);
document.getElementById("reset").addEventListener("click", resetTimer);



//FUNCTIONS

init();

function init(){
    activity = "Work";
    timerOn = false;  
    paused = false;
    resetProgressBar();
    
    //DOM
    document.getElementById(durWork).textContent = minWork;
    document.getElementById(durBreak).textContent = minBreak;
    UITimer.textContent = minWork + ":00";
    UIMessage.textContent = "";

}

function overlayOff(){
    document.getElementById("about-overlay").style.display = "none";
}

function overlayOn(){
    document.getElementById("about-overlay").style.display = "block";
}


function playTimer(){
    
    UIMessage.textContent = activity.toUpperCase();
    
    
    
    //if timer is not already on, start it
    if (!timerOn){
        timerOn = true;
        //determine whether to start from the beginning or continue from when it was paused
        if (!paused){
            progressBarIncrement();
            seconds = 59;
            minWork = document.getElementById(durWork).textContent;
            minBreak = document.getElementById(durBreak).textContent;
            console.log("start timer from 0");
        } else {
            paused = false;
            seconds = pausedSecond-1;
            minWork = pausedMinute + 1; 
            console.log("resume timer");
        }
        
        
        if (activity === "Work"){
            startTimeInterval(minWork, seconds); 
            //startProgressBar(minWork, seconds)
        } else if (activity === "Break"){
            startTimeInterval(minBreak, seconds);
            //startProgressBar(minBreak, seconds)
        }
        
        
        
    } else {
       //if timer is currently running, pause the timer and progress bar
        timerOn = false;
        clearInterval(timer);
        paused = true;
        pausedTime = UITimer.textContent;

        pausedMinute = pausedTime.match(/\d+(?=:)/);
        pausedMinute = parseInt(pausedMinute[0]);

        pausedSecond = pausedTime.match(/\d+$/);
        pausedSecond = parseInt(pausedSecond[0]);
      
    }
}

function progressBarIncrement(){
    if (activity === "Work" && minWork === 1 ){
        timeLeft = 59;
    } else if (activity === "Work" && minWork > 1){
        timeLeft = ((minWork-1) * 60) + 59;
    } else if (activity === "Break" && minBreak === 1 ){
        timeLeft = 59;
    } else if (activity === "Break" && minBreak > 1){
        timeLeft = ((minBreak-1) * 60) + 59;
    }
    barIncrement = 100/timeLeft;
}
    

function startTimeInterval(m, s){      
            //console.log("m: " + m + ", s: " + s);
    
        m--;
        progressBarOn = true;
        
    
        timer = setInterval(function(){
                
    
        
            if (s < 10){
                UITimer.textContent = m + ":0" + s;
            } else {
                UITimer.textContent = m + ":" + s;
            }
            s--;
                
            //progress bar
            if(width <= 100){
                console.log(width);
                width += barIncrement;
                UIBar.style.width = width + "%";
            }
                
                if(m > 0 && s < 0){
                    m--;
                    s = 59;
                } else if (m === 0 && s < 0){
                    clearInterval(timer);
                    if (activity === "Work"){
                        UIMessage.textContent = "Break starting in 3 seconds";
                        //sound.play();
                        activity = "Break";
                        timerOn = false;
                        resetProgressBar();
                        setTimeout(playTimer, 3000);
                    } else if (activity === "Break"){
                        UIMessage.textContent = "Back to work in 3 seconds";
                        //sound.play();
                        activity = "Work";
                        timerOn = false;
                        resetProgressBar();
                        setTimeout(playTimer, 3000);
                    }
                    
                }
        
            }, 1000);
        }
        

function resetTimer(){
    clearInterval(timer);
    init();
}


function resetProgressBar(){
    progressBarOn = false;
    width = 0;
    UIBar.style.width = width + "%";
}


            
          
!
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