Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                <h1>Pomodoro Timer</h1>

<div id="app"></div>
              
            
!

CSS

              
                /**
 * Add box sizing to everything
 * @link http://www.paulirish.com/2012/box-sizing-border-box-ftw/
 */
*,
*:before,
*:after {
	box-sizing: border-box;
}

/**
 * Layout
 */
body {
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
	font-size: 112.5%;
	margin-left: auto;
	margin-right: auto;
	max-width: 40em;
	width: 88%;
}

/**
 * Style the timer
 */
#timer {
	font-size: 2em;
	font-weight: bold;
}
              
            
!

JS

              
                //
// Variables
//

var countdown;


//
// Methods
//

/**
 * Play an alarm sound
 */
var alarm = function () {
    var alarm = new Audio('https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/Yodel_Sound_Effect.mp3');
    alarm.play();
};

/**
 * Add a leading 0 if none exists
 * @param  {Integer} num The number to pad
 * @return {String}      The padded number
 */
var padLeft = function (num) {
    if (num.toString().length < 2) {
        return `0${num}`;
    }
    return num;
};

/**
 * Reset the timer
 */
var reset = function () {
    timer.data.time = 1500;
};

var tick = function () {

    // Update the timer
    timer.data.time--;
    timer.data.running = true;

    // If the timer reaches zero, stop and sound an alarm
    if (timer.data.time === 0) {
        stop();
        alarm();
    }

};

/**
 * Start the timer
 */
var start = function () {

    // If the timer is at 0, reset it
    if (timer.data.time === 0) {
        reset();
    }

    // Start the timer
    tick();

    // Update the timer once a second
    countdown = window.setInterval(tick, 1000);

};

/**
 * Stop the timer
 */
var stop = function () {
    window.clearInterval(countdown);
    timer.data.running = false;
};

/**
 * Handle click events
 */
var clickHandler = function (event) {

    // Check if a timer action button was clicked
    var action = event.target.getAttribute('data-action');
    if (!action) return;

    // If it's the start button, start the timer
    if (action === 'start') {
        start();
        return;
    }

    // If it's the stop button, stop the timer
    if (action === 'stop') {
        stop();
        return;
    }

    // If it's the clear button, reset
    if (action === 'clear') {
        stop();
        reset();
    }

};


//
// Inits & Event Listeners
//

// Create the timer
var timer = new Reef('#app', {
    data: {
        time: 1500,
        running: false
    },
    template: function (props) {
        return `
            <div id="timer">
                ${parseInt(props.time / 60, 10).toString() + ':' + padLeft(props.time % 60)}
            </div>
            <p>
                <button data-action="${props.running ? 'stop' : 'start'}">${props.running ? 'Pause' : 'Start'}</button>
                <button data-action="clear">Reset</button>
            </p>`;
    }
});

// Render the timer into the DOM
timer.render();

// Listen for clicks
document.addEventListener('click', clickHandler, false);
              
            
!
999px

Console