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

              
                let {store, component} = reef;

// Create reactive store
let data = store({
    time: 1500,
    running: false
});

// Track counter
let countdown;

/**
 * Template
 */
function template () {
    return `
        <div id="timer">
            ${parseInt(data.time / 60, 10).toString() + ':' + (data.time % 60).toString().padStart(2, '0')}
        </div>
        <p>
            <button data-action="${data.running ? 'stop' : 'start'}">${data.running ? 'Pause' : 'Start'}</button>
            <button data-action="clear">Reset</button>
        </p>`;
}

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

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

/**
 * Count timer down by 1
 */
function tick () {

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

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

}

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

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

    // Start the timer
    tick();

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

}

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

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

    // Check if a timer action button was clicked
    let 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();
    }

}

// Render the timer into the DOM
component('#app', template);

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

Console