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.

            
              <div id="container">
  <h1>
    A Pomodoro Clock
  </h1>
  <div class="selectionOptions">
    Break length (minutes)<br>
    <button id="breakButtonMinus"
			 onclick="decrementBreakMinutes();">-</button>
    <input type="text" name="count" class="count" value="5"
           id="breakMinutes" >
    <button id="breakButtonPlus"
			 onclick="incrementBreakMinutes();">+</button>
  </div>
  
  <div class="selectionOptions">
    Session length (minutes)<br>
    <button id="sessionButtonMinus"
			 onclick="decrementSessionMinutes();">-</button>
    <input type="text" name="count" class="count" value="25"
           id="sessionMinutes" >
    <button id="sessionButtonPlus"
			 onclick="incrementSessionMinutes();">+</button>
  </div> <!-- End of selectionOptions div -->
	
  <div id="timer">
    <h3 id="sessionMessage">Start your session:</h3>
    <input type="text" name="minutes" id="minutes" value="25">
    min.
    <input type="text" name="seconds" id="seconds" value="0">
    sec.
  </div> <!-- End of timer div -->
	
  <input type="button" name="startButton" 
         id="startButton" value="Start Timer"
         onclick="startTimer();" >
	<input type="button" name="stopButton" 
         id="stopButton" value="Stop Timer"
         onclick="stopTimer();" >
</div> <!-- End of container div -->
            
          
!
            
              body { background-color: #000; }

#container { text-align: center;
             color: #FFF;
             font-family: Arial, Helvetica,
             sans-serif; }

.selectionOptions { display: inline-block;
                    padding-top: 10px;
                    padding-bottom: 10px;
                    padding-right: 40px;
                    padding-left: 40px; }

#breakButtonPlus, #breakButtonMinus, #sessionButtonPlus,
#sessionButtonMinus
{ margin-right: 10px;
	color: #FFF;
	border: none;
	background-color: transparent;
	text-decoration: none;
	font-size: 60px; }

.count { border: none;
         color: #FFF;
         background-color: transparent;
         font-size: 50px;
         width: 65px; }

#timer { font-size: 30px;
         padding-bottom: 20px; }

#minutes, #seconds, #timeUpMessage {
					 border: none;
           background-color: transparent;
           color: #FFF;
           width: 80px; 
           font-size: 50px; }

#startButton { border: 1px solid #FFF;
                border-radius: 10px;
                color: #FFF;
                background-color: green;
                padding: 10px;
                font-size: 20px; }

#startButton { margin-right: 20px; }

#stopButton { border: 1px solid #FFF;
                border-radius: 10px;
                color: #FFF;
                background-color: red;
                padding: 10px;
                font-size: 20px; }
            
          
!
            
              /* Default values for all settings (break and session length, and clock minutes/seconds) */
var defaultBreakLength = 5;
var defaultSessionLength = 25;
var defaultMinutes = 25;
var defaultSeconds = 0;
var secondsResetValue = 59;
var breakFlag = 0;
var timeout = 0;
document.getElementById("breakButtonMinus").
disabled = true;
document.getElementById("breakButtonMinus").
style.color = "grey";
document.getElementById("breakButtonPlus").
disabled = true;
document.getElementById("breakButtonPlus").
style.color = "grey";
document.getElementById("stopButton").disabled = true;
document.getElementById("stopButton").style.color = "grey";

var breakLengthMinutes =
		document.getElementById("breakMinutes").value;
var clockMinutes =
		document.getElementById("minutes").value;
var clockSeconds =
		document.getElementById("seconds").value;
var secondsCountedDown;
var ding = new Audio("https://s3-us-west-2.amazonaws.com/s.cdpn.io/1321144/Airplane-ding-sound.mp3");

function startTimer()
{	
	if(breakFlag == 0)
	{
		updateSessionMessage(1);
	}
	else
	{
		updateSessionMessage(2);
	}
	
	toggleLengthButtons();
	
	document.getElementById("startButton").disabled = true;
	document.getElementById("startButton").style.color = "grey";
	document.getElementById("stopButton").disabled = false;
	document.getElementById("stopButton").style.color = "white";
	
  secondsCountedDown =
    setInterval("countdown()", 1000);
}

function stopTimer()
{
	document.getElementById("startButton").disabled = false;
	document.getElementById("startButton").style.color = "white";
	document.getElementById("stopButton").disabled = true;
	document.getElementById("stopButton").style.color = "grey";
	updateSessionMessage(5);
	clearInterval(secondsCountedDown);
}

/* Manages the countdown of the session timer */
function countdown()
{	
  if(clockSeconds == -1)
  {
    clockSeconds
      = secondsResetValue;
		clockMinutes--;
		updateMinutes();
  }
	
	updateSeconds();
	
	if(clockMinutes == 0 &&
		clockSeconds == 0 && breakFlag == 0)
	{
		breakFlag = 1; /* Take a break; session is over */
		ding.play();
		
		updateSessionMessage(2);
		
		toggleLengthButtons();
		
		clockMinutes = breakLengthMinutes;
	}
	
	if(clockMinutes == 0 &&
		clockSeconds == 0 && breakFlag == 1)
	{
		breakFlag = 0; /* Break is over; new session begins */
		ding.play();
		
		updateSessionMessage(1);
		
		toggleLengthButtons();
		
		clockMinutes = defaultSessionLength;
	}
	
	clockSeconds--;
	
} /* End of countdown function */

/* Increments the session length minutes by one minute
	 for each click of the "+" button; also changes the
	 minutes on the clock with the same value */
function incrementSessionMinutes()
{
	document.getElementById("startButton").disabled = false;
	document.getElementById("startButton").style.color = "white";
	document.getElementById("stopButton").disabled = true;
	document.getElementById("stopButton").style.color = "grey";
	updateSessionMessage(3);
	
	clearInterval(secondsCountedDown);
	
	clockSeconds = defaultSeconds;
	updateSeconds();
	
	clockMinutes =
		++document.getElementById("sessionMinutes").value;
	updateMinutes();
} /* End of incrementSessionMinutes function */

/* Decrements the session length minutes by one minute
	 for each click of the "-" button; also changes the
	 minutes on the clock with the same value */
function decrementSessionMinutes()
{
	document.getElementById("startButton").disabled = false;
	document.getElementById("startButton").style.color = "white";
	document.getElementById("stopButton").disabled = true;
	document.getElementById("stopButton").style.color = "grey";
	updateSessionMessage(3);
	
	clearInterval(secondsCountedDown);
	
	clockSeconds = defaultSeconds;
	updateSeconds();
	
	clockMinutes = 
		--document.getElementById("sessionMinutes").value;
	updateMinutes();
	
	if(clockMinutes == 0)
	{
		clockMinutes = 1;
		document.getElementById("sessionMinutes").value =
			clockMinutes;
		updateMinutes();
	}
} /* End of decrementSessionMinutes function */

function incrementBreakMinutes()
{
	document.getElementById("startButton").disabled = false;
	document.getElementById("startButton").style.color = "white";
	document.getElementById("stopButton").disabled = true;
	document.getElementById("stopButton").style.color = "grey";
	updateSessionMessage(4);
	
	clearInterval(secondsCountedDown);
	
	clockSeconds = defaultSeconds;
	updateSeconds();
	
	clockMinutes =
		++document.getElementById("breakMinutes").value;
	updateMinutes();
} /* End of incrementBreakMinutes function */

function decrementBreakMinutes()
{
	document.getElementById("startButton").disabled = false;
	document.getElementById("startButton").style.color = "white";
	document.getElementById("stopButton").disabled = true;
	document.getElementById("stopButton").style.color = "grey";
	updateSessionMessage(4);
	
	clearInterval(secondsCountedDown);
	
	clockSeconds = defaultSeconds;
	updateSeconds();
	
	clockMinutes = 
		--document.getElementById("breakMinutes").value;
	updateMinutes();
	
	if(clockMinutes == 0)
	{
		clockMinutes = 1;
		document.getElementById("breakMinutes").value =
			clockMinutes;
		updateMinutes();
	}
} /* End of decrementMinutes function */

function updateSeconds()
{
	document.getElementById("seconds").value =
    clockSeconds;
}

function updateMinutes()
{
	document.getElementById("minutes").value = 
		clockMinutes;
}

/* Updates the message displayed according to what the
	 user or the clock is currently doing */
function updateSessionMessage(messageCode)
{
	switch(messageCode)
	{
		case 0:
			document.getElementById("sessionMessage")
			.innerHTML = "Start your session:";
			break;
		case 1:
			document.getElementById("sessionMessage")
			.innerHTML = "New session in progress:";
			break;
		case 2:
			document.getElementById("sessionMessage")
			.innerHTML = "Break in progress:";
			break;
		case 3:
			document.getElementById("sessionMessage")
			.innerHTML = "Changing session length:";
			break;
		case 4:
			document.getElementById("sessionMessage")
			.innerHTML = "Changing break time:";
			break;
		case 5:
			document.getElementById("sessionMessage")
			.innerHTML = "Clock paused";
	}
} /* End of updateSessionMessage code */

/* Toggles the active status of the break and session length 
	 buttons and changes their color to grey if they are disabled */
function toggleLengthButtons()
{
	if(breakFlag == 0)
	{
		document.getElementById("breakButtonMinus").
			disabled = true;
		document.getElementById("breakButtonMinus").
			style.color = "grey";
		document.getElementById("breakButtonPlus").
			disabled = true;
		document.getElementById("breakButtonPlus").
			style.color = "grey";
		document.getElementById("sessionButtonMinus").
			disabled = false;
		document.getElementById("sessionButtonMinus").
			style.color = "white";
		document.getElementById("sessionButtonPlus").
			disabled = false;
		document.getElementById("sessionButtonPlus").
			style.color = "white";
	}
	else
	{
		document.getElementById("breakButtonMinus").
			disabled = false;
		document.getElementById("breakButtonMinus").
			style.color = "white";
		document.getElementById("breakButtonPlus").
			disabled = false;
		document.getElementById("breakButtonPlus").
			style.color = "white";
		document.getElementById("sessionButtonMinus").
			disabled = true;
		document.getElementById("sessionButtonMinus").
			style.color = "grey";
		document.getElementById("sessionButtonPlus").
			disabled = true;
		document.getElementById("sessionButtonPlus").
			style.color = "grey";
	}
} /* End of toggleLengthButtons function */
            
          
!
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.

Console