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

              
                <link href="https://fonts.googleapis.com/css2?family=Bree+Serif&family=Raleway&display=swap" rel="stylesheet">

<h1>Teamer</h1>
        <h2>Make the Perfect Cuppa</h2>
        <div class="tea-buttons">

        </div>
        <div class="tea-timer">
            <div class="time-controls minute-controls">
                <button aria-label="Add 1 minute" type="button" class="minute-add" title="Add 1 minute" value="60">&#x2B06;</button>
                <button type="button" aria-label="Subtract 1 minute" class="minute-subtract" title="Subtract 1 minute" value="-60">&#x2B07;</button>
            </div>
            <span class="minute">00</span>:<span class="second">00</span> 
            <div class="time-controls second-controls">
                <button aria-label="Add 10 seconds" type="button" class="second-add" title="Add 10 seconds" value="10">&#x2B06;</button>
                <button type="button" aria-label="Subtract 10 seconds" class="second-subtract" title="Subtract 10 seconds" value="-10">&#x2B07;</button>
            </div>
            <div class="play-controls">
                <button type="button" class="play-pause" value="0">&#x23EF;</button>
                <button type="button" class="stop" value="0">&#x23F9;</button>
                <p class="error"></p>
            </div>
        </div>
        <audio class="alarm" src="http://lisefrac.net/teamer/219244__zyrytsounds__alarm-clock-short.wav"></audio>
        <aside class="credit-disclaimer">
            <p>Tea steeping times and temperatures via <a href="http://blog.davidstea.com/en/hot-stuff-tea-steeping-temperatures/">David's Tea</a>.</p>
            <p>Tea steeping is a contentious topic; when available, we recommend using the time/temperature on the container.</p>
            <p><a href="https://freesound.org/people/ZyryTSounds/sounds/219244/" target="_blank">"Alarm clock short"</a> sound effect by <a href="https://freesound.org/people/ZyryTSounds/" target="_blank">ZyryTSounds on Freesound.org</a></p>
        </aside>
              
            
!

CSS

              
                body {
    margin:1rem;
    font-family: 'Raleway', sans-serif;
}
a {
    color:#094161;
    font-weight:bold;
}
button {
    cursor:pointer;
}
a:hover, a:active {
    color:#278cc0;
}
h1 {
    font-size:3rem;
    margin:0;
    text-align:center;
    font-family: 'Bree Serif', serif;
}
h2 {
    text-align:center;
    font-family: 'Raleway', sans-serif;
}
h3 {
    font-family: 'Bree Serif', serif;
    text-align:center;
}
.tea-buttons {
    display: flex;
    margin: 2rem auto;
    justify-content: center;
    flex-wrap:wrap;
}
.tea-btn {
    border-radius:50%;
    padding:0;
    margin:1rem;
    min-width:100px;
    flex:1;
    position:relative;
    border-width:1px;
    border-style:dashed;
    /* colors will be set in JS from teas Object */
}
.tea-btn:before {
    content: "";
    display: inline-block;
    padding-top: calc(100% - 2px);/* account for borders on parent*/
}
.tea-btn h3 {
    position:absolute;
    top:3%;
    left:0;
    right:0;
    font-size: 1.25rem;
}
.steeping-instructions {
    position: absolute;
    bottom: 10%;
    left: 0;
    right: 0;
    font-family: 'Raleway', sans-serif;
    font-size:14px;
}
.tea-timer {
    text-align: center;
    display: flex;
    font-family: 'Raleway', sans-serif;
    font-size: 3rem;
    border: 1px solid #000;
    margin: 2rem auto;
    width: 40%;
    padding: 1rem;
    justify-content: center;
    align-items: center;
    line-height: 3rem;
    flex-wrap:wrap;
}
.time-controls {
    display:flex;
    flex-direction:column;
    flex-wrap:nowrap;
    margin:0 0.75rem;
}
.play-controls {
    width: 100%;
    margin:0;
}
.play-controls button {
    background: none;
    border: none;
    font-size: 26px;
    padding:0;
}
.credit-disclaimer {
    text-align:center;
    font-family: 'Raleway', sans-serif;
    font-style:italic;
}

.error {
    color:red;
    font-size:1rem;
    opacity:0;
    transition:opacity 0.3s
}

@media screen and (min-width: 48em) {
    .tea-timer {
        width: 30%;
    }
}
              
            
!

JS

              
                const teas = {
    "white": {
        "displayName": "white",
        "tempC" : 90,
        "tempF": 195,
        "timeFloor": 3,
        "timeCeiling": 5,
        "bgColor":"#b2e1d9",
        "textBorderColor": "#094161"
    },
    "green": {
        "displayName": "green",
        "tempC" : 85,
        "tempF": 185,
        "timeFloor": 2,
        "timeCeiling": 4,
        "bgColor":"#b3db78",
        "textBorderColor": "#fff"
    },
    "oolong": {
        "displayName": "oolong",
        "tempC" : 90,
        "tempF": 195,
        "timeFloor": 4,
        "timeCeiling": 5,
        "bgColor":"#278cc0",
        "textBorderColor": "#fff"
    },
    "black": {
        "displayName": "black",
        "tempC" : 95,
        "tempF": 200,
        "timeFloor": 3,
        "timeCeiling": 5,
        "bgColor":"#224A6D",
        "textBorderColor": "#fff"
    },
    "puerh": {
        "displayName": "pu'erh",
        "tempC" : 95,
        "tempF": 200,
        "timeFloor": 4,
        "timeCeiling": 5,
        "bgColor":"#9D667E",
        "textBorderColor": "#fff"
    },
    "mate": {
        "displayName": "mat&eacute;",
        "tempC" : 95,
        "tempF": 200,
        "timeFloor": 4,
        "timeCeiling": 5,
        "bgColor":"#D6166B",
        "textBorderColor": "#fff"
    },
    "rooibos": {
        "displayName": "rooibos",
        "tempC" : 95,
        "tempF": 200,
        "timeFloor": 4,
        "timeCeiling": 5,
        "bgColor":"#FD8F18",
        "textBorderColor": "#fff"
    },
    "herbal": {
        "displayName": "herbal",
        "tempC" : 95,
        "tempF": 200,
        "timeFloor": 5,
        "timeCeiling": 6,
        "bgColor":"#A0A956",
        "textBorderColor": "#094161"
    }
}
const second = document.querySelector('.second');
const minute = document.querySelector('.minute');
const teaBox = document.querySelector(".tea-buttons");
const playPause = document.querySelector(".play-pause");
const stop = document.querySelector(".stop");
const timeControlsBtns = document.querySelectorAll(".time-controls button");
let playing=false;
//console.log("setting initial value of playing to false");
let ticker;
const errorBox = document.querySelector(".error");
const alarm = document.querySelector(".alarm");

function loadTeas() {
    Object.keys(teas).forEach(key => {
        // console.log(teas[key].displayName);
        const currentTea = teas[key];
        let btn = document.createElement("button");
        btn.type = "button";
        btn.value = key;
        btn.classList.add("tea-btn");
        btn.innerHTML = `
        <h3>${currentTea.displayName}</h3>
        <div class="steeping-instructions">
            <div class="temp">&#x1F321 ${currentTea.tempF}&deg;F (${currentTea.tempC}&deg;C)</div>
            <div class="time">&#x23F3 ${currentTea.timeFloor}-${currentTea.timeCeiling} min</div>
        </div>`;
        btn.style.backgroundColor = currentTea.bgColor;
        btn.style.color = currentTea.textBorderColor;
        btn.style.borderColor = currentTea.textBorderColor;
        btn.addEventListener("click", function() {
            setTimer(currentTea.timeCeiling, 0);
        });
        teaBox.appendChild(btn);
    });
    
}//loadTeas() declaration

function setTimer(min, sec) {
    minute.textContent = min.toString().padStart(2, '0');
    second.textContent = sec.toString().padStart(2, '0');
    playPause.value = (min * 60 * 1000) + (sec * 1000); //add time in ms to value of play/pause button
    
}
function playTimer() {
    const ms = parseInt(playPause.value);
    if (ms === 0) {
        error("you need to add time to the timer");
    }
    else {
        const startTime = Date.now();
        const deadline = startTime + ms;
        playing=true;
        //console.log("setting playing to true");
        //I'm setting the interval to not-quite-one-second to avoid jumps/gaps in the countdown
        //Should not affect deadline, only the interval at which the current time is calculated and displayed
        ticker = setInterval(tick, 990, deadline); 
    }
}
function tick(end) {
    let now = Date.now();
        if (end > now) {//time hasn't elapsed yet
            let diffMs = end - now;
            let diffMin = Math.floor(diffMs / 60000);
            let diffRemSec = Math.floor(diffMs % 60000 / 1000 );            
            setTimer(diffMin, diffRemSec);
                    
        }
        else {//time has elapsed
            stopTicker();
            setTimer(0,0);
            playAlarm();
        }
}
function stopTicker() {
    clearInterval(ticker);
    playing=false;
    //console.log("set playing to false");
}
function error(msg) {
    console.error(`Teamer error: ${msg}`);
    errorBox.textContent = msg;
    errorBox.style.opacity = "1";
}
function deError() {
    errorBox.textContent = "";
    errorBox.style.opacity = "0";
}
function playAlarm() {
    alarm.currentTime = 0;
    alarm.play();
}
function stopAlarm() {
    alarm.pause();
    alarm.currentTime = 0;
}

window.addEventListener("load", loadTeas);

playPause.addEventListener("click", function() {
    deError();
    stopAlarm();
    if (playing === true) {
        stopTicker();
    }
    else {
        playTimer();
    }
    
});
stop.addEventListener("click", function() {
    deError();
    stopAlarm();
    stopTicker();
    setTimer(0,0);
});
timeControlsBtns.forEach(function(btn) {
    btn.addEventListener("click", function() {
        stopAlarm();
        let mins = parseInt(minute.textContent);
        let secs = parseInt(second.textContent);
        switch (parseInt(btn.value)) {
            case 60:
                deError();
                setTimer(mins+1, secs);
                break;
            case -60:
                if (mins === 0) {
                    setTimer(0, 0);
                }
                else setTimer(mins-1, secs);
                break;
            case 10:
                deError();
                if (secs > 49) {
                    setTimer(mins+1, (secs+10)-60);
                }
                else setTimer(mins, secs+10);
                break;
            case -10:
                if (secs < 10 && mins === 0) {
                    setTimer(0, 0);
                }
                else if (secs < 10) {
                    setTimer(mins-1, (secs-10)+60);
                }
                else setTimer(mins, secs-10);
                break;
        }
        if (playing === true) {
            stopTicker();
            playTimer(); //if timer is running, run playTimer() to update the deadline; otherwise it will update when the play/pause button is clicked again
        }
    });
    
});
              
            
!
999px

Console