Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="container">
  <h1>Pomodoro Timer</h1>
  <h3>a freeCodeCamp Project</h3>
    <div id="mainDisplay">
      <div id="innerDisplay">
        <span id="time"></span> 
      </div>
      <button onclick="startPause()" id="startPause">Start</button>
      <button onclick="reset()" id="reset">Reset</button>
    </div>
  
    <div id="outerTA">
      <div class="timeAdjust" id="workA">
        <p>Work</p>
        <div>
          <button onclick="workLess()">-1</button>
          <span id="currentWT"></span>
          <button onclick="workMore()">+1</button>
        </div>
      </div>
      <div class="timeAdjust" id="restA">
        <p>Play</p>
        <div>
          <button onclick="restLess()">-1</button>
          <span id="currentRT"></span>
          <button onclick="restMore()">+1</button>
        </div>
      </div>
    </div>
  
</div>
              
            
!

CSS

              
                /* colour scheme : wed11 on coolors.co */
body, html {
  text-align: center;
  font-size: 16px;
  font-family: Impact, sans-serif;
  background-color: #2D2D2A;
  color: #E5DCC5;
  padding:  0;
  margin: 0;
  min-width: 300px;
}

h1 {
  color: #2D2D2A;
  font-size: 3em; 
  margin: 5px auto;
  text-align: left;
}

h3 {
  color: #2D2D2A;
  margin: 0 auto 10px auto;
  text-align: right;
}

button {
  background: #4C4C47;
  padding: 10px;
  margin: 10px;
  color: #E5DDC5;
  font-weight: bold;
  text-transform: uppercase;
  border: 2px solid #2D2D2A;
  border-radius: 5px;
}

#container {
  width: 100%;
  height: 100%;
  margin: 0 auto;
  overflow: auto;
  background: #4C4C47;
  padding: 20px 15px 0 15px;
}

#time {
  font-size: 7em;
}

#currentRT, #currentWT {
  font-size: 2em;
}

#innerDisplay {
  background-color: #4C4C47;
  border-radius: 3px;
  padding: 10px;
  height: 150px;
  line-height: 150px;
}

#mainDisplay {
  width: 90%;
  margin: auto;
  background: #4C4C47;
}

#outerTA {
  margin: auto;
  width: 85%;
  height: 100%;
  background: #788585;
}

#workA, #restA {
  display: inline-block;
  width: auto;
  margin: 10px;
  color: #788585;
  background: #4C4C47;
  border-radius: 3px;
}

#workA, #currentWT {
  color: #C14953;
}

@media only screen and (min-width: 500px) {
  body {
    padding: 50px 0;
  }
  
  #container {
    width: 70%;
  }

  #outerTA {
    width: 70%;
    margin-bottom: 25px;
  }
  
}

@media only screen and (min-width: 900px) {
  
  #container {
    width: 60%;
  }
  
  #outerTA {
    width: 80%;
  }

  
}
              
            
!

JS

              
                //declarations and setting up 'static' display
var workT = 25;
  if (workT < 10) {workT = "0" + workT;};
var restT = 2;
  if (restT < 10) {restT = "0" + restT};
//audio for timer taken from FreeSFX
var alarm = new Audio("http://www.freesfx.co.uk/rx2/mp3s/9/10275_1369687679.mp3");
var running = 0;
var target = workT;
var mins = target;
var counter = document.getElementById("time");
var seconds = 60;
var tock;
var setRest = 0;

// setting up display of work/rest time
function wtRt() {
    if (running == 1 && setRest == 0) {
      document.getElementById("innerDisplay").style.background = "#C14593";
    }
    if (running == 1 && setRest == 1) {
      document.getElementById("innerDisplay").style.background = "#788585";

    }
    if (running == 0) {
        document.getElementById("innerDisplay").style.background = "#4C4C47";
    }
}

//initial time display
document.getElementById("currentWT").innerHTML = workT + ":00";
document.getElementById("currentRT").innerHTML = restT + ":00";
counter.innerHTML = target + ":00";

//buttons to change time variables
function workLess() {
  if (workT > 5) {
    workT == workT--;
        if (workT < 10) {workT = "0" + workT;};
    target = workT;
    mins = target;
    counter.innerHTML = target + ":00";
    document.getElementById("currentWT").innerHTML = workT + ":00";
  }
  else {
    alert("Please work for at least five minutes!")
  }
}

function workMore() {
  workT == workT++;
      if (workT < 10) {workT = "0" + workT;};
  target = workT;
  mins = target;
  counter.innerHTML = target + ":00";
  document.getElementById("currentWT").innerHTML = workT + ":00";
}

function restLess() {
  if (restT > 1) {
    restT == restT--;
        if (restT < 10) {restT = "0" + restT;};
    document.getElementById("currentRT").innerHTML = restT + ":00";
  }
  else{
  alert("Take a break! Rest for at least a minute!")
 }
}

function restMore() {
  restT == restT++;
      if (restT < 10) {restT = "0" + restT;};
  document.getElementById("currentRT").innerHTML = restT + ":00";
}

//guts of the timer
function tick() {
    var currentMinutes = mins - 1;

  if (running === 1) {
      seconds--;
      counter.innerHTML = (currentMinutes < 10 ? "0" : "") + currentMinutes.toString() + ":" + (seconds < 10 ? "0" : "") + String(seconds);
      if (seconds > 0) {
       tock = window.setTimeout(tick, 1000);
      } else {
        seconds = 60;
        mins = mins - 1;
        if (mins >= 1) {
         setTimeout(function() {countdown(mins-1);}, 1000);
      }  
        else{
          if (setRest == 0){
            setRest = 1;
          alarm.play();
          restSet();
          }
          else{
            running = 0;
            setRest = 0;
         timeUp();
               document.getElementById("startPause").innerHTML ="Start";
           
          }
        }
        
  }
  }

  wtRt();

}

function countdown(minutes) {
  target = minutes;
  tick(); 
}

function workSet() {
  countdown();
}

function restSet() {
  setRest = 1;
target = restT;
mins = target;
  counter.innerHTML = target + ":00";
  countdown();  
}

function timeUp() {
  alarm.play();
  counter.innerHTML = "Done!";
}

//start/pause reset functions
function startPause() {
  if (running === 0) {
    running = 1;
    document.getElementById("startPause").innerHTML ="Pause";
    workSet();
  }
 
 else {
   running = 0;
   document.getElementById("startPause").innerHTML = "Resume";
  }
}

function reset() {
  running = 0;
  setRest = 0;
  window.clearTimeout(tock);
  target = workT;
  mins = target;
  seconds = 60;
  counter.innerHTML = target + ":00";
  document.getElementById("startPause").innerHTML = "Start";
  
}

              
            
!
999px

Console