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

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.

            
              <div id="container">
    <h1 class="title">FreeCodeCamp Pomodoro</h1>
    <div class="box">
      <input id="work" type="number" value="25"/>
      <input id="break" type="number" value="5"/>
    </div>
    <div class="box">
      <button id='startBtn'>Start</button>
      <button id='killClock'>Stop</button>
      <button id='resetClock'>Reset</button>
    </div>
    <div>
      <h1 class="title">Countdown</h1>
      <div class="counter">
        <div id="countdown" class='biggest'>0:00</div>
        <div id="endTime"></div>
        <div id="alerts"></div>
      </div>
    </div>
</div>
            
          
!
            
              * { padding: 0; border: 0; box-sizing: border-box;}
html,body{
	font-family: Helvetica, sans-serif;
	font-size: 16px;
	background-color: #e1e2ea;//#4B4E6D;
}
body {
	display: flex;
	justify-content: center;
	align-items: center;
	height: 50vh;
	transform: translatey(50%);
}
#container {
	display: flex;
	flex-direction: column;
	width: 320px;
	margin-top: 10px;
}

.box {
	display: flex;
}
.box button {
  font-size: 2rem;
  box-shadow: 2px 2px 2px 0px rgba(0,0,0,0.4);
  //background-color: #F46036;
  margin-left: 16px;
  margin-top: 10px;
  padding: 5px;
}
#startBtn {
  background-color: green;
  &:hover {
    background-color: #3cff3c;
  }
}
//
#killClock {
  background-color: #D7263D;
  &:hover {
    background-color: #e05063;
  }
}
#resetClock {
  background-color: #262B89;
  &:hover {
    background-color: #6369d4;
  }
}
.title {
	padding: 10px 0;
}

.counter {
	display: flex;
	flex-direction: column;
	justify-content: center;
	height: 200px;
	border: 1px white solid;
	border-radius: 0 0 20px 0;
	background-color: #D7263D;

}

.counter, .title, .btn {
		box-shadow: 2px 2px 2px 0px rgba(0,0,0,0.4);
}

//Utilities
h1, h2, p, input, button, .biggest, #alerts, #endTime {
	text-shadow: 1px 1px 2px rgba(0,0,0,.39),
					-1px -1px 2px rgba(0,0,0,.39);
	text-align: center;
	color: #FFFFFF;
}
h1, h2, p {
	background-color: #F46036; // #67637E;
	margin-bottom: 0;
}
.biggest {
  font-size: 5rem;
}
input {
	width: calc(320px/2);
	font-size: 5rem;
	border: 1px darkgray solid;
	box-shadow: 2px 2px 2px 0px rgba(0,0,0,0.4);
}
input:nth-of-type(1){
	background-color: #262B89;
}
input:nth-of-type(2){
	border-radius: 0 0 20px 0;
	background-color: #D82940;
}

            
          
!
            
              // Zipline: Build a Pomodoro Clock: https://www.youtube.com/watch?v=lgj3nfzV0xM&t=10s
// Rules You may use any APIs or libraries & Reverse engineer projects functionality
// Functionality Demo: https://codepen.io/gstorbeck/full/RPbGxZ
// Userstory: User can starts a 25min countdown punctuated by an alarm at zero; then it self-reinitiates until the user stops it. 
// Also user can stop and start the Pomodoro and optionally change the length of each Pomodoro; doesn't specify which option should be changeable e.g. breaktime or pomodoro itself.
// .setInterval(). for repeating components ex. the 25min timer
//.setTimeout() for the non-repeating component or the part that can be re-called ex. the break of 5min can use settimeout.
const startClock = getSelector('#startBtn')
const killSwitch = getSelector('#killClock')
const resetClockSelect = getSelector('#resetClock')
const countDown = getSelector('#countdown')
const endTime = getSelector('#endTime')
const alerts = getSelector('#alerts')

let sessionCount = 5;
let clockTimeRemaining;
let breakTimeRemaining;
let timer;
let breakTimer;
let minInputWork;
let minEndTimeBreak;
let startDate;
let sessionTime;

function loadClock(){
  startDate = Date.now()
  minInputWork = convertToMillies(parseInt(getSelector('#work').value))
  minEndTimeBreak = convertToMillies(parseInt(getSelector('#break').value))
  const endTimeTotal = startDate + (minInputWork + minEndTimeBreak) * 5
  displayEndTime(endTimeTotal)
  clock()
}

function clock() {
  if(sessionCount > 0) {
    startWorking();
    sessionCount = sessionCount - 1;
    alerts.textContent = ''
    countDown.textContent = '0:00'
  } else {
    sessionCount = 5
    endTime.textContent = ''
    countDown.textContent = '0:00'
    alerts.textContent = `Click 'Start' button to start again`
  }
}

function startWorking (){
  sessionTime = Date.now()
  if (sessionCount < 0) {
    clearInterval(timer);
    console.log('called timer sessionCount')
  }
  timer = setInterval(() => {
    clockTimeRemaining = Math.floor((getEndDate(sessionTime, minInputWork) - Date.now())/1000); // Seconds
    console.log('working time: ', clockTimeRemaining)
    if (clockTimeRemaining === 0) {
      clearInterval(timer);
      startBreak(sessionTime);
    }
    getTime(clockTimeRemaining)
  }, 1000);
}


function startBreak(sessionTime) {
  if (sessionCount < 0) {
    clearInterval(breakTimer);
    console.log('called breakTimer sessionCount')
  }
  breakTimer = setInterval(() => {
    breakTimeRemaining = Math.floor((getEndBreakDate(sessionTime, minInputWork, minEndTimeBreak) - Date.now())/1000);
    console.log('break time: ', breakTimeRemaining)
    if (breakTimeRemaining === 0) {
      clearInterval(breakTimer);
      clock()
    }

    getTime(breakTimeRemaining)

  }, 1000);

}
/* getTime and displayEndTime are courtesy of JS30 @ Wes Bos: Thank you for the amazing video on clocks! */
function getTime (seconds) {
  const minutes = Math.floor(seconds/60);
  const remainderSeconds = seconds % 60;
  const display = `${minutes}:${remainderSeconds < 10 ? "0":""}${remainderSeconds}`
  document.title = display
  countDown.textContent = display
}
function displayEndTime (timestamp) {
  const end = new Date (timestamp)
  const hours = end.getHours()
  const minutes = end.getMinutes()
  endTime.textContent = `Your Pomodoro Timer will end at ${hours}:${minutes < 10 ? "0":""}${minutes} `
}
/* getTime and displayEndTime are courtesy of JS30 @ Wes Bos: Thank you for the amazing video on clocks! */


function resetClock() {
  sessionCount = 5
  countDown.textContent = '0:00'
  endTime.textContent = ''
  alerts.textContent = `Pomodoro Reset! Start Again`
  clearInterval(timer);
  clearInterval(breakTimer);
  console.log(sessionCount)
}
function killClock (){
  sessionCount = 0
  clearInterval(timer);
  clearInterval(breakTimer);
  clock()
}

function getEndDate(startDate, minInputWork) {
  return startDate + minInputWork;
}

function getEndBreakDate(startDate, minInputWork, minEndTimeBreak) {
  return startDate + minInputWork + minEndTimeBreak;
}

function convertToMillies(minutes){
  return minutes * 60000
}

// Listeners
startClock.addEventListener('click', loadClock)
killSwitch.addEventListener('click', killClock)
resetClockSelect.addEventListener('click', resetClock)

// Utility
function getSelector(cssSelect){
	return document.querySelector(cssSelect)
}
            
          
!
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