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.

            
              head
  meta( name="viewport" content="width=device-width, initial-scale=1")
  link(rel="stylesheet", href="/css/font-awesome.min.css")
  link(rel="stylesheet", href="/css/pomodoro.css")
  script(rel="text/javascript", src="/js/pomodoro.js").
  title Pomodoro by John Mica

body

  .logos Developed by 
    a( href="https://www.freecodecamp.com/JohnMica" target="_blank") John Mica
  header
    h2 This is my version of the Pomodoro clock
    h2 for FreeCodeCamp
  main
    p#tomato     What you want to do
    .controls 
      .tomato
        #diffColors

      .workBtns
        span.title Work for
        button.buttonSpecial#workplus 
          span
            i.fa.fa-plus 
        span#worktime 
        button.buttonSpecial#workminus 
          span
            i.fa.fa-minus 
        span.min  min
      .display
        input(type="text", disabled )#display

      .breakBtns 
        span.title Break for
        button.buttonSpecial#breakplus 
          span
            i.fa.fa-plus
        span#breaktime 
        button.buttonSpecial#breakminus 
          span
            i.fa.fa-minus
        span.min  min

    .buttons
      button#start.changeBtn(type='Btn') Start
      button#pause.changeBtn(type='Btn') Pause
      button#reset.changeBtn(type='Btn') Reset
      button#startBreak.changeBtn(type='Btn') Start
      button#pauseBreak.changeBtn(type='Btn') Pause
      button#resetBreak.changeBtn(type='Btn') Reset
      br
    .descr
      p adjust the timer by clicking the

      span
        button.minus(disabled) -
        button.plus(disabled) +
      p press start and keep working 
  footer
    p Feel free to play with the code, change and update

            
          
!
            
              *
    box-sizing: border-box
body
    position: relative
    text-align: center
    padding-top: 2em
    margin: auto
    min-height: 100%
.logos
    text-align: right
    padding-right: 2em
header
    margin: 2em
main
    position: relative
    height: auto
    margin-top: 9em
    padding-bottom: 6em
#tomato
    margin-top: 5em
    position: relative
    width: 100%
    font-size: 1.4em

.controls
    position: relative
    display: flex
    justify-content: space-around
    flex-flow: row wrap
    align-items: center
    width: 80%
    margin: 0 auto
    padding: 0
.tomato
    position: absolute
    height: 400px
    width: 400px
    left: 50%
    top: 50%
    transform: translate(-50%, -50%)
    z-index: -1
    border-radius: 50%

.title
    width: 100%
    display: block
    font-style: oblique
    font-weight: bold
    font-size: 1.2em
    margin-bottom: 10px
.min
    display: block
    width: 100%
input
    text-align: center
    font-size: 1.6em
    line-height: 1.7em
    position: relative
    background-color: rgba(139, 207, 84, 0.5)
    box-shadow: none
    border: none
    border-radius: 5px
    background-image: linear-gradient(to bottom, #a9db80, #96c56f)
.descr
    height: auto
    margin-top: 5em
    position: relative
button
    focus: none
    outline: none
#worktime, #breaktime
    vertical-align: middle
    padding: 6px
    font-size: 1.2em
.changeBtn
    border: 1px solid #8bcf54
    box-shadow: #B4B5B5 1px 1px 1px
    border-radius: 0
    font-size: 1.2em
    padding: 10px 10px 10px 10px
    margin: -2px
    text-decoration: none
    display: inline-block
    text-shadow: 0px 0px 0 rgba(0,0,0,0.3)
    font-weight: bold
    color: #edf6f7
    background-color: #8bcf54
    background-image: linear-gradient(to bottom, #a9db80, #96c56f)
    focus: none
    &:hover
        background-image: linear-gradient(to bottom, #8ed058, #7bb64b)
.buttonSpecial
    border: 0px solid #8bcf54
    font-size: 16px
    font-family:palatino linotype, palatino, serif
    padding: 16px 16px 16px 16px
    text-decoration: none
    display: inline-block
    color: #edf6f7
    background-image: linear-gradient(to bottom, #a9db80, #96c56f)
    &:hover
        background-image: linear-gradient(to bottom, #8ed058, #7bb64b)

    span
        vertical-align: middle
.buttons
    position: relative
footer
    position: absolute
    bottom: 0
    left: 0
    right: 0
    padding: 1em
    width: 100%

#breaktime, #worktime
    display: inline-block
    padding: 5px 10px
    text-align: center
#breakminus, #workminus
    border-radius: 0px 50px 3px 50px
#breakplus, #workplus
    border-radius: 50px 0px 50px 3px

            
          
!
            
              window.onload = function () {

    'use strict';

        var countdown,
          delay = 1000,
          session = 5,
          rest = 1,
          currentTime,
          sessionTimeSecs,          
          breakTimeSecs,
          workSec = session * 60,
          restSec = rest * 60,
          workAudio = new Audio ('http://www.freesfx.co.uk/rx2/mp3s/5/16924_1461333030.mp3'),
          breakAudio = new Audio('https://notificationsounds.com/soundfiles/c45147dee729311ef5b5c3003946c48f/waveform.png'),
          worktime = document.getElementById('worktime'),
          workminus = document.getElementById('workminus'),
          workplus = document.getElementById('workplus'),
          breaktime = document.getElementById('breaktime'),
          breakminus = document.getElementById('breakminus'),
          breakplus = document.getElementById('breakplus'),
          timer = document.getElementById('display'),
          startBttn = document.getElementById('start'),
          pauseBttn = document.getElementById('pause'),
          resetBtn = document.getElementById('reset'),
          startBreakBtn = document.getElementById('startBreak'),
          pauseBreakBtn = document.getElementById('pauseBreak'),
          resetBreakBtn = document.getElementById('resetBreak'),
          tomato = document.getElementById('tomato'),
          currentState = 'session';

        timer.value = worktime.innerHTML = ' ' + session + ":00" + ' ';
        breaktime.innerHTML = ' ' + rest + ':00' + ' ';

        function displayWork(start, pause, reset) {
          startBttn.style.display = start;
          pauseBttn.style.display = pause;
          resetBtn.style.display = reset;
        }

        function displayBreak(start, pause, reset) {
          startBreakBtn.style.display = start;
          pauseBreakBtn.style.display = pause;
          resetBreakBtn.style.display = reset;
        }

        displayWork('', '', '');
        displayBreak('none', 'none', 'none');

        function startCountdown(seconds) {
          var minutes = parseInt(seconds / 60),
              leftSec = seconds % 60;
          if (leftSec < 10) {
            leftSec = '0' + leftSec;
          }
            timer.value = minutes + ':' + leftSec;
        }

        function startWork() {

          tomato.innerHTML = 'Working time ....';
          currentState = 'session';
          if (timer.value == worktime.innerHTML) {
              workAudio.play();
          }

          clearInterval(countdown);
          countdown = setInterval(function() {
            startCountdown(workSec);

            if (workSec === 0) {
              clearInterval(countdown);
              restSec = rest * 60;
              displayWork('none', 'none', 'none');
              timer.value = breaktime.innerHTML;
              startBreak();
            } else {
              workSec--;
            }
          }, delay);
          displayWork('', '', '');
          draw();
        }

        function startBreak() {
            tomato.innerHTML = 'break time ...';
            currentState = 'break';
          if (timer.value == breaktime.innerHTML) {
              breakAudio.play();
          }

            clearInterval(countdown);
            countdown = setInterval(function() {
              startCountdown(restSec);

              if (restSec === 0) {
                clearInterval(countdown);
                workSec = session * 60;
                displayBreak('none', 'none', 'none');
                displayWork('', '', '');
                timer.value = worktime.innerHTML;
                tomato.innerHTML = 'Break is over ... start work again ???';

              } else {
                restSec--;
              }

            }, delay);
            displayBreak('', '', '');
            draw();
        }

        function pauseWork() {
          clearInterval(countdown);
          displayWork('', '', '');
          startBttn.innerHTML = 'Resume';
        }

        function pauseBreak() {
          clearInterval(countdown);
          displayBreak('', '', '');
          startBreakBtn.innerHTML = 'Resume';
        }

        function resetWork() {
          pauseWork();
          workSec = session * 60;
          timer.value = worktime.innerHTML = session + ':00';
          startBttn.innerHTML = 'Start';
          tomato.innerHTML = ' ... start work again ???';
        }

        function resetBreak() {
          pauseBreak();
          restSec = rest * 60;
          timer.value = breaktime.innerHTML= rest + ':00';
          startBreakBtn.innerHTML = 'Start';
          tomato.innerHTML = '... start break again ???';
        }

        function substractWork() {
          session--;
          if (session < 0) {
            session = 0;
          }
          workSec = session * 60;
          timer.value =  worktime.innerHTML = ' ' + session + ':00' + ' ';
        }

        function subtractBreak() {
          rest--;
          if (rest < 0) {
            rest = 0;
          }
          restSec = rest * 60;
          breaktime.innerHTML = ' ' + rest + ':00' + ' ';
        }

        function addWork() {
          session++;
          workSec = session * 60;
          timer.value =  worktime.innerHTML = ' ' + session + ':00' + ' ';
        }

        function addBreak() {
          rest++;
          restSec = rest * 60;
          breaktime.innerHTML = ' ' + rest + ':00' + ' ';
        }

 // update colors to rgba and margin inside ? to be done in future


        workminus.addEventListener('click', substractWork);
        workplus.addEventListener('click', addWork);
        breakminus.addEventListener('click', subtractBreak);
        breakplus.addEventListener('click', addBreak);
        startBttn.addEventListener('click', startWork);
        pauseBttn.addEventListener('click', pauseWork);
        resetBtn.addEventListener('click', resetWork);
        startBreakBtn.addEventListener('click', startBreak);
        pauseBreakBtn.addEventListener('click', pauseBreak);
        resetBreakBtn.addEventListener('click', resetBreak);


};



            
          
!
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