cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <h1> Pomodoro Clock </h1>
<div class = "controls">
<!--Session Timers Controls-->
<div id = "session">
<button id = "addWork"> + </button>
<h3> Work </h3>
<p class = "workInt"> </p>
<button id="minusWork"> - </button>
</div>
<!--Break Timer Controls-->
<div id = "break">
<button id="addBreak"> + </button>
<h3> Break </h3>
<!-- default time-->
<p class ="breakInt"> </p>
<button id="minusBreak"> - </button>
</div>
</div>
<div id="tomato-timer" class="text-center">
<div id="clock-top">
</div>
<div id= "clock" class="workTime">
<p class="type"> </p>
<p class="counter"> </p>
</div>
</div>
<div id="start-reset">
<button id="start-stop"> </button>
<button id="reset"> Reset </button>
</div>
            
          
!
            
              body {
  background: #331a00;
  color: #fff;
  text-align: center;
}

.controls {
  display: inline-block;
  margin-bottom: 5em;
}

.controls button{
  background: #004d00;
  color: #cc2900;
}

#break{
  display: inline;
  float: right;
  margin-left: 2em;
}

#session {
  display: inline;
  float: left;
  margin-right: 2em;
}

#clock {
  height: 22em;
  width: 22em;
  border-radius: 100%;
  border-width: .25em;
  border-style: solid;
  border-color:  #cc2900;
  background-color: #cc2900;
  margin: -45px auto;
  z-index: 1;
}

#clock p{
  text-align: center;
  font-size: 450%;
  margin: 40px auto;
}

#tomato-timer {
  clear: both;
}

#start-reset {
 margin: 5em 2em;
}

#start-reset button{
  background: #004d00;
  font-weight: bold;
  color: #cc2900;
  height: 3em;
  width: 5em;
  margin: 0em .5em;

}


#clock-top {
   margin: auto;
   position: relative;
   display: block;
   color: #004d00;
   width: 0px;
   height: 0px;
   border-right:  100px solid transparent;
   border-bottom: 70px  solid #004d00;
   border-left:   100px solid transparent;
   -moz-transform:    rotate(35deg);
   -webkit-transform: rotate(35deg);
   -ms-transform:     rotate(35deg);
   -o-transform:      rotate(35deg);
   z-index: -1;
}
#clock-top:before {
   border-bottom: 80px solid #004d00;
   border-left: 30px solid transparent;
   border-right: 30px solid transparent;
   position: absolute;
   height: 0;
   width: 0;
   top: -45px;
   left: -65px;
   display: block;
   content: '';
   -webkit-transform: rotate(-35deg);
   -moz-transform:    rotate(-35deg);
   -ms-transform:     rotate(-35deg);
   -o-transform:      rotate(-35deg);
   z-index: -1;

}
#clock-top:after {
   position: absolute;
   display: block;
   color: #004d00;
   top: 3px;
   left: -105px;
   width: 0px;
   height: 0px;
   border-right: 100px solid transparent;
   border-bottom: 70px solid #004d00;
   border-left: 100px solid transparent;
   -webkit-transform: rotate(-70deg);
   -moz-transform:    rotate(-70deg);
   -ms-transform:     rotate(-70deg);
   -o-transform:      rotate(-70deg);
   content: '';
   z-index: -1;
}


            
          
!
            
              //set init var
//times in seconds 
var time = {
  work: 1500,
  break: 300,
};
var timeOutput;

var count = time.work;
  //storing function in var to be able to stop timer
var timer ;
var audio = new Audio('255101__soneproject__jingle2.wav');
//intinal setup of variables in html for buttons and type 
$("p.type").html("Work");
$("#start-stop").html("Start");


//Take in seconds and returns string xx:xx
function timeDisplay(timeInput){
  var minCon = timeInput/60
  var min = (Math.floor(minCon)).toString();
  var sec = (timeInput%60).toString();
  //adding 0s if second or min is only one char long
  if(min.length == 1 && sec.length != 1){
    console.log("min padding added");
    var paddedMin = "0" + min;
    timeOutput =  paddedMin + ":" + sec;
  }else if(sec.length == 1 && min.length != 1){
    console.log("sec padding added");
    var paddedSec= "0" + sec;
    timeOutput =  min + ":" + paddedSec;
  } else if(min.length == 1 && sec.length == 1){
  console.log("both min & sec padding added")
    var paddedMin = "0" + min;
    var paddedSec= "0" + sec;
   timeOutput =  paddedMin + ":" + paddedSec;
  }else {
  timeOutput =  min + ":" + sec;
  };
  console.log(timeOutput)
  return timeOutput;
}

//intinal setup of var in html where time is dispalyed on page
$("p.counter").html(timeDisplay(count));
$("p.workInt").html(timeDisplay(time.work));
$("p.breakInt").html(timeDisplay(time.break));

function addWork() {
    time.work += 60;
    count = time.work;
    $("p.workInt").html(timeDisplay(count));
    //updating count var to change with work
    $("p.counter").html(timeDisplay(count));
  };

function minusWork() {
    //on - button click subtract 1 to Work interval
    time.work -= 60;
    count = time.work;
     $("p.counter").html(timeDisplay(count));
     $("p.workInt").html(timeDisplay(count));
    //avoiding non-existant and negative intervals
    if(time.work >= 1) {
      //updating count var to change with work
      $("p.workInt").html(timeDisplay(count));
      // timeDisplay();
    } else {
      time.work = 1;
      count = time.work;
    }  
  };

function addBreak() {
    //on + button click add 1 to Break     interval
    time.break += 60;
    $("p.breakInt").html(timeDisplay(time.break));
  };

function minusBreak() {
    //on - button click subtract one from break interval
  time.break -= 60;
  //avoiding non-existant and negative intervals
  if (time.break >= 1) {
    $("p.breakInt").html(timeDisplay(time.break));
  } else {
    time.break = 1;
  }
};

function reset() {
    if($("#clock").hasClass("workTime") == false){
    $("#clock").addClass("workTime");
    }
    count = time.work;
    console.log("timer reset")    
    $("p.counter").html(timeDisplay(count));
  };


function checkStatus() {
  //setting work vs break sessions
  if($("#clock").hasClass("workTime") == true) {
    $("p.type").html("Work");
      count = time.work
     $("p.counter").html(timeDisplay(time.work));
  } else {
     $("p.type").html("Break")
      count = time.break;
      $("p.counter").html(timeDisplay(time.break));
  };
};


function countDown(){
    if (count >= 1) {
      count -= 1;
      console.log(count);
      $("p.counter").html(timeDisplay(count));
    } else if(count == 0)  {
      console.log("switch")
      console.log(count)
      //play alarm
      audio.play();
       $("#clock").toggleClass("workTime");
       checkStatus();
    }
  };
  
$('#addWork').click(function(){
    addWork();
});

$('#minusWork').click(function() {
    minusWork();
});

$('#addBreak').click(function() {
    addBreak();
});

$('#minusBreak').click(function() {
    minusBreak();
});

//reset count to work time
$("#reset").click(function() {
    reset();
  
});

$("#start-stop").click(function() {
  $("#start-stop").toggleClass("running");
    console.log("timer toggled");
    //Toggling start and stop button
    if ($("#start-stop").hasClass("running") == true) {
     timer = setInterval(function(){ countDown()}, 1000);
      $("#start-stop").html("Stop");
    } else {
      clearInterval(timer);
      $("#start-stop").html("Start");
    };
  });

            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console