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

              
                <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>

<div id="clock">
  <h1>Pomodoro Clock</h1>
  <div class="adjust">
    <h2 id="session-label">Session Length</h2>
    <p>
      <i id="session-decrement" class="material-icons" onclick="decSession()">remove</i>
      <span id="session-length">25</span>
      <i id="session-increment" class="material-icons" onclick="incSession()">add</i>
  </div>
  <div class="adjust">
    <h2 id="break-label">Break Length</h2>
    <p>
      <i id="break-decrement" class="material-icons" onclick="decBreak()">remove</i> <span id="break-length">5</span>
      <i id="break-increment" class="material-icons" onclick="incBreak()">add</i>
    </p>
  </div>
  <div id="countdown">
    <h2 id="timer-label">"Session!"</h2>
    <p id="time-left">25:00</p>
    <p>
      <span id="start_stop" onclick="startStop()">
          <i class="material-icons">play_circle_outline</i>
          <i class="material-icons">pause_circle_outline</i> 
        </span>
      <span id="reset">
          <i class="material-icons" onclick="resetTimes()">replay</i>
        </span>
    </p>
  </div>
</div>
<audio id="beep"><source src="http://soundbible.com/mp3/ie_Short_Cow_MooMeow_Mix_Comm-KevanGC-2007570186.mp3" type="audio/mpeg"></audio>
              
            
!

CSS

              
                body {
  font-family: "Comic Sans MS"; 
  color: #4a4236;
  background-color: #E3E8EB;
  background-image: url(https://i.pinimg.com/originals/6d/53/be/6d53be6e608c3e5fdb27e1d98bd818da.jpg);
  background-size: 250px;
  background-repeat: no-repeat; 
  background-attachment: fixed;
  background-position: left bottom; 
}

#clock {
  margin: auto;
  margin-top: 50px;
  background-color: #f0f3f4;
  width: 400px;
  height: 350px;
  text-align: center; 
  border: 2px solid #C15A51;
  border-radius: 15px;
  display: grid; 
  grid-template-rows: 1fr 1fr 1fr; 
  grid-template-columns: 1fr 1fr; 
}

h1 {
  grid-column: 1 / 3;
  line-height: 0.6;
}

#countdown {
  grid-column: 1 / 3; 
}

p { 
  font-size: 26px; 
  line-height: 0.6;
}

i:hover, 
i:active {
  color: #C15A51;
  cursor: pointer;
}


/*reddish pink #C15A51;
 soft brown #A37858; 
pusheen dark gray #685D4B
              
            
!

JS

              
                // TO DO: Use this icon and toggleClass with play and mute to make them turn red when active <i class="material-icons">volume_off</i>

//////////////////////////////////////////
// Function to make minutes display 2 digits
function twoDigits(number) {
  if (number < 10) {
    number = "0" + number;
    console.log(number);
    return number;
  }
  return number;
}

//////////////////////////////////////////
// Setting up global variables for user controls and time display

let timeLeft = document.getElementById("time-left");
let seconds = 0;
let breakLength = document.getElementById("break-length").innerText;
let sessionLength = document.getElementById("session-length").innerText;
let saveBreak = breakLength;
let saveSession = sessionLength;
timeLeft.innerHTML = `${sessionLength}:00`;

//////////////////////////////////////
// User control functionality
function decSession() {
  console.log(sessionLength);
  if (counting == true) {
    return;
  } else {
    if (saveSession > 1) {
      saveSession--;
      document.getElementById("session-length").innerText = saveSession;
      sessionLength = saveSession;
      seconds = 0;
      if (workTime == true) {
        document.getElementById("time-left").innerText = `${twoDigits(
          sessionLength
        )}:00`;
      }
    }
  }
}

function incSession() {
  if (counting == true) {
    return;
  } else {
    if (saveSession < 60) {
      saveSession++;
      document.getElementById("session-length").innerText = saveSession;
      sessionLength = saveSession;
      seconds = 0;
      if (workTime == true) {
        document.getElementById("time-left").innerText = `${twoDigits(
          sessionLength
        )}:00`;
      }
    }
  }
}

function decBreak() {
  console.log(breakLength);
  if (counting == true) {
    return;
  } else {
    if (saveBreak > 1) {
      saveBreak--;
      document.getElementById("break-length").innerText = saveBreak;
      breakLength = saveBreak;
      seconds = 0;
      if (workTime == false) {
        document.getElementById("time-left").innerHTML = `${twoDigits(
          breakLength
        )}:00`;
      }
    }
  }
}


function incBreak() {
    if (counting == true) {
    return;
  } else {
  if (saveBreak < 60) {
    saveBreak++;
     document.getElementById("break-length").innerText = saveBreak;
      breakLength = saveBreak;
      seconds = 0;
      if (workTime == false) {
        document.getElementById("time-left").innerText = `${twoDigits(
          breakLength
        )}:00`;
  }
  }
}
}

/////////////////////////////////////////////
// RESET BUTTON

function resetTimes() {
  clearInterval(myTimer);
  saveBreak = 5; 
  saveSession = 25;
  breakLength = 5;
  sessionLength = 25;
  workTime = true;
  counting = false; 
  setLabel(); 
  document.getElementById("break-length").innerText = breakLength;
  document.getElementById("session-length").innerText = sessionLength;
  seconds = 0;
  timeLeft.innerHTML = `${sessionLength}:00`;
  meow.currentTime = 0;
  meow.pause();
}

///////////////////////////////////
// PLAY-PAUSE BUTTON
let counting = false;
function startStop() {
  counting = !counting;
  if (counting) {
    myTimer = setInterval(timer, 1000);
  } else {
    clearInterval(myTimer);
    meow.currentTime = 0;
    meow.pause();
  }
}

//////////////////////////////////////
// SETTING THE TIMER LABEL

let workTime = true;
let timerLabel = document.getElementById("timer-label");

function setLabel() {
  if (workTime == true) {
    timerLabel.textContent = "Session!";
  } else {
    timerLabel.textContent = "Break!";
  }
}
setLabel();

/////////////////////////////////////////////
// AUDIO ELEMENT

const meow = document.getElementById("beep");
function playAudio() {
  meow.currentTime = 0;
  meow.play();
}

//////////////////////////////////////////
// WORK, REST, AND TIMER FUNCTIONS
function work() {
  setLabel();
  // Simplest, most likely case
  if (seconds > 0) {
    seconds--;
    document.getElementById("time-left").innerHTML = `${twoDigits(
      sessionLength
    )}:${twoDigits(seconds)}`;
  } else {
    // If seconds == 0
    if (sessionLength > 0) {
      sessionLength--;
      seconds = 59;
      document.getElementById("time-left").innerHTML = `${twoDigits(
        sessionLength
      )}:${seconds}`;
    } else {
      // If seconds == 0 && sessionLength == 0!!!
      playAudio();
      console.log(sessionLength);
      workTime = false;
      sessionLength = document.getElementById("session-length").innerText;
      breakLength = document.getElementById('break-length').innerText; 
      document.getElementById("time-left").innerHTML = `${twoDigits(
        breakLength
      )}:${twoDigits(seconds)}`;
    }
  }
}

function rest() {
  setLabel();
  // Simplest, most likely case
  if (seconds > 0) {
    seconds--;
    document.getElementById("time-left").innerHTML = `${twoDigits(
      breakLength
    )}:${twoDigits(seconds)}`;
  } else {
    // If seconds == 0
    if (breakLength > 0) {
      breakLength--;
      seconds = 59;
      document.getElementById("time-left").innerHTML = `${twoDigits(
        breakLength
      )}:${seconds}`;
    } else {
      // If seconds == 0 && sessionLength == 0!!!
      playAudio();
      workTime = true;
      breakLength = document.getElementById("break-length").innerText;
      sessionLength = document.getElementById("session-length").innerText;
      document.getElementById("time-left").innerHTML = `${twoDigits(
        sessionLength
      )}:${twoDigits(seconds)}`;
    }
  }
}

function timer() {
  if (workTime) {
    work();
  } else {
    rest();
  }
}

/* 
Old inc and dec functions in case this is a bust 
function decBreak() {
  if (breakLength > 1) {
    breakLength --;
    document.getElementById("break-length").innerText = breakLength;
   if ((workTime == false)) {
      document.getElementById("time-left").innerHTML = `${twoDigits(
        breakLength
      )}:00`;
    } 
  }
      seconds = 0;

}

function incBreak() {
  if (breakLength < 60) {
    breakLength ++;
  } 
    seconds = 0;

    document.getElementById("break-length").innerText = breakLength;
    if ((workTime == false)) {
      document.getElementById("time-left").innerHTML = `${twoDigits(
        breakLength
      )}:00`;
    } 
  }
  */

              
            
!
999px

Console