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="root"></div>
<!-- Old code - need to be rewritted without using 'date' to pass test and allow for 1 hour to display as 60 minutes

var date = new Date(null);
date.setSeconds(25 * 60);
var timeString = date.toISOString().substring(14, 19);
var paused = true;
class PomodoroApp extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			breakLength: 5,
			sessionLength: 25,
			timeLeft: timeString,
			timerMode: 'Session'
		}
		this.setTime = this.setTime.bind(this);
		this.clickHandler = this.clickHandler.bind(this);
		this.runTimer = this.runTimer.bind(this);
		this.tick = this.tick.bind(this);
		this.reset = this.reset.bind(this);
	}
	setTime(seconds) {
		date = new Date(null);
		date.setSeconds(seconds * 60);
		timeString = date.toISOString().substring(14, 19);
	}
	clickHandler(e) {
		console.log(this.state.timeLeft);
		switch (e.currentTarget.id) {
			case 'session-decrement':
				if(this.state.sessionLength > 1){
					this.setTime(this.state.sessionLength - 1);
					this.setState({
						sessionLength: this.state.sessionLength - 1,
						timeLeft: timeString
					});
				}
				break;
			case 'session-increment':
				if(this.state.sessionLength < 60 ){
					this.setTime(this.state.sessionLength + 1);
					this.setState({
						sessionLength: this.state.sessionLength + 1,
						timeLeft: timeString
					});
				}
				break;
			case 'break-decrement':
				if(this.state.breakLength > 1){
					this.setState({
						breakLength: this.state.breakLength - 1
					});
				}
				break;
			case 'break-increment':
				if(this.state.breakLength < 60 ){
					this.setState({
						breakLength: this.state.breakLength + 1
					});
				}
				break;
		}
	}
	tick() {
		console.log(timeString);
		if( ((date.getMinutes() * 60) + date.getSeconds()) > 0 ) {
			date.setSeconds(date.getSeconds() - 1);
			timeString = date.toISOString().substring(14, 19);
			this.setState({
				timeLeft: timeString
			})
		} 
		else {
			if (this.state.timerMode === 'Break') {
				this.setTime(this.state.sessionLength);
				this.setState({
					timerMode: 'Session'
				})
			} else {
				this.setTime(this.state.breakLength);
				this.setState({
					timerMode: 'Break'
				})
			}
		}
	}
	runTimer(e) {
		var self = this;
		paused = !paused;
		var runInterval = setInterval(function(){
			if(!paused){
				self.tick();
			}
		}, 1000)
		// if(date.getMinutes() < this.state.sessionLength){
		// 	console.log(runInterval);
		// 	clearInterval(runInterval);
		// }
	}
	reset() {
		//clearInterval(runInterval);
		date = new Date(null);
		date.setSeconds(25 * 60);
		timeString = date.toISOString().substring(14, 19);
		paused = true;
		this.setState({
			breakLength: 5,
			sessionLength: 25,
			timeLeft: timeString
		})
	}
	
	render() {
		return(
			<div id="clock-container">
				<h1>Pomodoro Clock</h1>
				<div className="grid-50">
					<div id="break-label">Break Length</div>
					<span id="break-decrement" onClick={this.clickHandler}><i class="fas fa-arrow-down"></i></span>
					<span id="break-length">{this.state.breakLength}</span>
					<span id="break-increment" onClick={this.clickHandler}><i class="fas fa-arrow-up"></i></span>
				</div>
				<div className="grid-50">
					<div id="session-label">Session Length</div>
					<span id="session-decrement" onClick={this.clickHandler}><i class="fas fa-arrow-down"></i></span>
					<span id="session-length">{this.state.sessionLength}</span>
					<span id="session-increment" onClick={this.clickHandler}><i class="fas fa-arrow-up"></i></span>
				</div>
				<div className="grid-100">
					<div id="timer-label">{this.state.timerMode}</div>
					<div id="time-left">{timeString}</div>
					<div className="controls-container">
						<div id="start_stop" className="grid-50" onClick={this.runTimer}><i class="fas fa-play"><i class="fas fa-pause-circle"></i></i></div>
						<div id="reset" className="grid-50" onClick={this.reset}><i class="fas fa-sync"></i></div>
					</div>
				</div>
			</div>
		)
	}
}

ReactDOM.render(
	<PomodoroApp />,
	document.getElementById("root")
);

-->
              
            
!

CSS

              
                body, html, #root {
	display: grid;
	height: 100%;
	margin: 0;
}
body {
	background: #4D7191;
	font-family: Arial;
	color: white;
	&.break {
		background: #B8653F;
	}
}
#fcc_test_suite_wrapper {
	display: contents;
}

// elements
#clock-container {
	max-width: 600px;
	text-align: center;
	margin: auto;
	h1 {
		margin: 0;
		opacity: .2;
		font-size: 10.1vw;
		@media screen and (min-width: 660px) {
			font-size: 74.9px;
		}
		top: -20px;
		position: relative;
	}
	#time-left {
		font-size: 32vw;
		@media screen and (min-width: 660px) {
			font-size: 241px;
		}
		line-height: .8em;
		padding: 15px 0 20px 0;
	}
	.time-control {
		padding: 15px 0;
	}
	#break-length, #session-length {
		font-size: 25px;
		padding: 0 10px;
	}
	#timer-label {
		text-transform: uppercase;
		letter-spacing: 10px;
		padding-left: 2%;
	}
	.controls-container {
		position: relative;
	}
	#reset {
		width: auto;
		position: absolute;
		right: 11px;
		top: 50%;
		transform: translateY(-50%);
	}
}

// icons
.fas::before{
	position: relative;
	bottom: 2px;
}
.fa-play-circle, .fa-pause-circle {
	font-size: 70px;
	&.hide{
		display: none;
	}
}

// Grid
[class*="grid"] {
	padding-top: 10px;
}
.grid-50 {
	width: 50%;
	display: inline-block;
}
.grid-100 {
	width: 100%;
}
              
            
!

JS

              
                var paused = true;
var minutes, seconds, secondsTotal, timeString, runInterval;
class PomodoroApp extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			breakLength: 5,
			sessionLength: 25,
			timeLeft: '',
			timerMode: 'Session'
		}
		this.setTime = this.setTime.bind(this);
		this.clickHandler = this.clickHandler.bind(this);
		this.runTimer = this.runTimer.bind(this);
		this.tick = this.tick.bind(this);
		this.reset = this.reset.bind(this);
	}
	setTime(s) {
		var timeArr = (s / 60).toString().split('.');
		minutes = timeArr[0];
		seconds = Math.round(Number(('.' + timeArr[1]) * 60));
		if(minutes.length < 2) {
			minutes = 0 + minutes;
		}
		if(isNaN(seconds)) {
			seconds = '00';
		} else if(seconds.toString().length < 2) {
			seconds = 0 + seconds.toString();
		}
		secondsTotal = (Number(minutes) * 60) + Number(seconds);
		timeString = minutes + ':' + seconds;
	}
	clickHandler(e) {
		switch (e.currentTarget.id) {
			case 'session-decrement':
				if(this.state.sessionLength > 1 && paused){
					this.setTime((this.state.sessionLength - 1) * 60);
					this.setState({
						sessionLength: this.state.sessionLength - 1,
						timeLeft: timeString
					});
				}
				break;
			case 'session-increment':
				if(this.state.sessionLength < 60 && paused){
					this.setTime((this.state.sessionLength + 1) * 60);
					this.setState({
						sessionLength: this.state.sessionLength + 1,
						timeLeft: timeString
					});
				}
				break;
			case 'break-decrement':
				if(this.state.breakLength > 1 && paused){
					this.setState({
						breakLength: this.state.breakLength - 1
					});
				}
				break;
			case 'break-increment':
				if(this.state.breakLength < 60 && paused){
					this.setState({
						breakLength: this.state.breakLength + 1
					});
				}
				break;
		}
	}
	tick() {
		if(secondsTotal > 0) {
			this.setTime(secondsTotal - 1);
			this.setState({
				timeLeft: timeString
			})
		} 
		else {
			document.getElementById('beep').play();
			if (this.state.timerMode === 'Break') {
				this.setTime(this.state.sessionLength * 60);
				this.setState({
					timerMode: 'Session'
				})
				document.querySelector('body').classList.remove('break');
			} else {
				this.setTime(this.state.breakLength * 60);
				this.setState({
					timerMode: 'Break'
				})
				document.querySelector('body').classList.add('break');
			}
		}
	}
	
	runTimer(e) {
		var timerIcons = document.querySelectorAll('#start_stop i');
		for (var i = 0; i < timerIcons.length; i++) {
			if(timerIcons[i].className.includes('hide')){
				timerIcons[i].classList.remove('hide');
			} else {
				timerIcons[i].classList.add('hide');
			}
		}
		var self = this;
		paused = !paused;
		if(!paused){
			runInterval = setInterval(self.tick, 1000)
		} else {
			clearInterval(runInterval);
		}
	}
	reset() {
		paused = true;
		clearInterval(runInterval);
		this.setTime(25 * 60);
		this.setState({
			breakLength: 5,
			sessionLength: 25,
			timeLeft: timeString,
			timerMode: 'Session'
		})
		document.getElementById('beep').pause();
		document.getElementById('beep').currentTime = 0;
	}
	
	componentDidMount(){
		this.setTime(this.state.sessionLength * 60);
		this.setState({timeLeft: timeString});
	}
	
	render() {
		return(
			<div id="clock-container">
				<h1>Pomodoro Clock</h1>
				<div className="grid-50 time-control">
					<div id="break-label">Break Length</div>
					<span id="break-decrement" onClick={this.clickHandler}><i class="fas fa-arrow-down"></i></span>
					<span id="break-length">{this.state.breakLength}</span>
					<span id="break-increment" onClick={this.clickHandler}><i class="fas fa-arrow-up"></i></span>
				</div>
				<div className="grid-50 time-control">
					<div id="session-label">Session Length</div>
					<span id="session-decrement" onClick={this.clickHandler}><i class="fas fa-arrow-down"></i></span>
					<span id="session-length">{this.state.sessionLength}</span>
					<span id="session-increment" onClick={this.clickHandler}><i class="fas fa-arrow-up"></i></span>
				</div>
				<div className="grid-100">
					<div id="timer-label">{this.state.timerMode}</div>
					<div id="time-left">{timeString}</div>
					<div className="controls-container">
						<div id="start_stop" className="grid-100" onClick={this.runTimer}><i className="fas fa-play-circle"></i><i className="fas fa-pause-circle hide"></i></div>
						<div id="reset" className="grid-100" onClick={this.reset}><i class="fas fa-sync"></i></div>
					</div>
				</div>
				<audio id="beep" src="https://cdnjs.cloudflare.com/ajax/libs/ion-sound/3.0.7/sounds/bell_ring.mp3"></audio>
			</div>
		)
	}
}

ReactDOM.render(
	<PomodoroApp />,
	document.getElementById("root")
);
              
            
!
999px

Console