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

              
                
<!DOCTYPE html>
<html>
    <head>
        <script src="https://unpkg.com/react@16/umd/react.development.js"
            crossorigin></script>
        <script
            src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"
            crossorigin></script>
        <script
            src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
        <style>
            body {
            background-color: #222;
            max-width: 900px;
            margin: 5em auto;
            color: #999;
            font-family: Arial, Helvetica, sans-serif;
            text-align: center;

            }

            button {
            display: inline-block;
            margin-right: 5px
            }

            .card {
            background-color: #FFF;
            text-align: center;
            padding: 100px;
            }

            .counter {
                width: 30%;
                display: inline-block
            }

            .timer {
                font-size: 4em;
                color: #222;
                width: 250px;
                background-color: #FFF;
                margin: 0 auto;
                margin-bottom: 0.5em;
            }
        </style>
        <title>Counter</title>
    </head>

    <body>
        <div id="app"></div>
        <script type="text/babel">
            var pause = true;
            var myInt;
            var tempDuration;


            class Counter extends React.Component {
                render() {
                    return (
                    <div>
                        <h3 id={this.props.name}>{this.props.count}</h3>
                    </div>
                    )
                }
            }

            class Timer extends React.Component {
                render() {
                return (
                <div>
                    <h1 className="timer" id="time-left">
                        {this.props.duration / 60 < 10 ? "0" + Math.floor(this.props.duration / 60) : Math.floor(this.props.duration / 60)}:{this.props.duration % 60 < 10 ? "0" + this.props.duration % 60 : this.props.duration % 60}
                    </h1>

                </div>
                )
                }
            }

            class App extends React.Component {
                constructor(props) {
                    super(props);
                    this.state = {
                        breakCounter: 5,
                        sessionCounter: 25,
                        duration: 1500,
                        type: "Session"
                    }
                }

                render() {
                    return (
                    <div>
                        <h1>25-5 Clock</h1>
                        <div className="counter">
                            <h3 id="break-label">Break Length</h3>
                            <Counter
                                name="break-length"
                                count={this.state.breakCounter} />

                            <button id="break-decrement" onClick={(e) => this.decrement(e, "break")}>-</button>
                            <button id="break-increment" onClick={(e) => this.increment(e, "break")}>+</button>
                        </div>
                        
                        <div className="counter">
                            <h3 id="session-label">Session Length</h3>
                            <Counter
                                name="session-length"
                                count={this.state.sessionCounter} />

                            <button id="session-decrement" onClick={(e) => this.decrement(e, "session")}>-</button>
                            <button id="session-increment" onClick={(e) => this.increment(e, "session")}>+</button>
                        </div>

                        <h1 id="timer-label">{this.state.type}</h1>
                        <Timer 
                        duration={this.state.duration}
                        />

                        <button id="start_stop" onClick={(e) => this.countdown(this.state.duration)}>Start/Stop</button>
                        <button id="reset" onClick={this.reset}>Reset</button>
                        <audio id="beep" preload="auto" src="https://cdn.freecodecamp.org/testable-projects-fcc/audio/BeepSound.wav"></audio>
                    </div>
                    )
                }

                increment = (e, type) => {
                    if (this.state.type === "Session" && type === "session") {
                    this.setState(state => {
                        return {
                            sessionCounter: state.sessionCounter === 60 ? state.sessionCounter : state.sessionCounter + 1,
                            duration: state.duration === 60*60? state.duration: (state.sessionCounter +1) * 60
                        }
                    })
                    }

                    if (this.state.type === "Session" && type === "break") {
                    this.setState(state => {
                        return {
                            breakCounter: state.breakCounter === 60 ? state.breakCounter : state.breakCounter + 1
                        }
                    })
                    }

                    if (this.state.type === "Break" && type === "break") {
                    this.setState(state => {
                        return {
                            breakCounter: state.breakCounter === 60 ? state.breakCounter : state.breakCounter + 1,
                            duration: state.duration === 60*60? state.duration:(state.breakCounter +1) * 60
                        }
                    })
                    }

                    if (this.state.type === "Break" && type === "session") {
                    this.setState(state => {
                        return {
                            sessionCounter: state.sessionCounter === 60 ? state.sessionCounter : state.sessionCounter + 1,
                        }
                    })
                    }
                }

                decrement = (e, type) => {
                    if (this.state.type === "Session" && type === "session") {
                    this.setState(state => {
                        return {
                            sessionCounter: state.sessionCounter === 1 ? state.sessionCounter : state.sessionCounter - 1,
                            duration: state.duration === 1*60? state.duration: (state.sessionCounter - 1) * 60
                        }
                    })
                    }

                    if (this.state.type === "Session" && type === "break") {
                    this.setState(state => {
                        return {
                            breakCounter: state.breakCounter === 1 ? state.breakCounter : state.breakCounter - 1
                        }
                    })
                    }
                    if (this.state.type === "Break" && type === "break") {
                    this.setState(state => {
                        return {
                            breakCounter: state.breakCounter === 1 ? state.breakCounter : state.breakCounter - 1,
                            duration: state.duration === 1*60? state.duration: (state.breakCounter - 1) * 60
                        }
                    })
                    }
                    if (this.state.type === "Break" && type === "session") {
                    this.setState(state => {
                        return {
                            sessionCounter: state.sessionCounter === 1 ? state.sessionCounter : state.sessionCounter - 1,
                        }
                    })
                    }
                }

                reset = () => {
                    pause = true            
                    document.getElementById("beep").pause()
                    document.getElementById("beep").currentTime = 0
                    clearInterval(myInt)        
                    this.setState(
                    {
                        duration: 1500,
                        breakCounter: 5,
                        sessionCounter: 25,
                        type: "Session"
                    })
                    }

                countdown = (duration) => {
                    if (pause === true) {
                    pause = false
                    myInt = setInterval(() => {
                        duration--
                        if (duration < 0) {
                        var beeping = this.beep(6000)
                        if(this.state.type === "Session") {
                            duration = this.state.breakCounter * 60 + 1
                            this.setState(state => {return {
                                type: "Break"
                            }})
                        }
                        else if (this.state.type === "Break") {
                            duration = this.state.sessionCounter * 60 + 1
                            this.setState(state => {return {
                                type: "Session"
                            }})
                        }
                        }
                        else {
                            this.setState(state => { return {
                                duration: duration
                            }})
                        }
                        }, 1000)
                    
                    }
                    else {
                    clearInterval(myInt)
                    pause = true
                    this.updateDuration()
                    }

                }

                updateDuration = () => {
                    let time = document.getElementById("time-left").innerHTML
                    let [min, sec] = time.split(":")
                    let newDuration = parseInt(min) * 60 + parseInt(sec)
                    this.setState({
                        duration: newDuration
                    })
                }

                beep = (msecs) => {
                    let beep = document.getElementById("beep")
                        beep.loop = true;
                        beep.play();
                        setTimeout(() => { beep.pause(); }, msecs);
                        }
                
            }



    ReactDOM.render(<App />, document.querySelector("#app"));

  </script>
        <script
            src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
    </body>

</html><!-- 

Hello Camper!

Please read the README below in the JS Editor before beginning. Feel free to delete this message once you have read it. Good luck and Happy Coding! 

- The freeCodeCamp Team 

-->

              
            
!

CSS

              
                
              
            
!

JS

              
                // !! IMPORTANT README:

// You may add additional external JS and CSS as needed to complete the project, however the current external resource MUST remain in place for the tests to work. BABEL must also be left in place. 

/***********
INSTRUCTIONS:
  - Select the project you would 
    like to complete from the dropdown 
    menu.
  - Click the "RUN TESTS" button to
    run the tests against the blank 
    pen.
  - Click the "TESTS" button to see 
    the individual test cases. 
    (should all be failing at first)
  - Start coding! As you fulfill each
    test case, you will see them go   
    from red to green.
  - As you start to build out your 
    project, when tests are failing, 
    you should get helpful errors 
    along the way!
    ************/

// PLEASE NOTE: Adding global style rules using the * selector, or by adding rules to body {..} or html {..}, or to all elements within body or html, i.e. h1 {..}, has the potential to pollute the test suite's CSS. Try adding: * { color: red }, for a quick example!

// Once you have read the above messages, you can delete all comments. 

              
            
!
999px

Console