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

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

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

CSS

              
                  body {
    padding-top: 80px;
    font-family: 'Righteous', cursive;
    text-align: center;
    background-color: #6ed0ec;
  }

  h2 {
    font-size: 1.8rem;
    color: white;
    margin-bottom: 10px;
  }

  h1 {
    color: white;
    font-size: 2.1rem;
  }

  .container {
    border: 5px solid #005670;
    margin: 0 auto;
    width: 600px;
    padding: 0 30px 30px 30px;
    border-radius: 15%;
    background-color: #0CA7D3;

  }

  #time-left {
    margin-bottom: 10px;
  }

  #break {
    float: left;
    display: flex;
    flex-direction: column;
  }

  #session {
    float: right;
    display: flex;
    flex-direction: column;
  }

  #inc-dec {
    margin-top: 150px;
  }

  #break-increment {
    margin-right: 340px;
    margin-left: 10px;
  }

  #break-decrement {
    margin-left: -20px;
  }

  #session-increment {
    margin-left: 10px;
  }

  p {
    margin-top: 0;
    margin-bottom: 0;
    font-size: 2rem;
    color: #005670;
  }

  #timer {
    border: 3px solid #005670;
    border-radius: 15%;
    margin-left: 200px;
    margin-right: 200px;
    padding-bottom: 20px;
    font-size: rem;
  }

  #reset {
    margin-top: 10px;
    color: #F95759;
  }

  h3 {
    color: #005670;
    font-size: 3rem;
    margin-top: 0;
  }

  button {
    font-size: 1rem;
    font-family: 'Share Tech Mono', monospace;
    border: none;
    background-color: #005670;
    color: white;
    padding: 5px 10px 5px 10px;
  }

  #copyright {
    font-size: 0.8rem;
    color: dark-grey;
    text-align: center;
    margin-top: 20px;
  }
              
            
!

JS

              
                let min = 0;
    let sec = 0;
    let counter = 0;
    let interval;
    let minutes = 0;
    let timeleft = 0;
    let seconds = 0;

    class App extends React.Component {
      constructor(props) {
        super(props);
        this.state = {
          type: "Session",
          status: "pause",
          sessionMins: "25",
          sessionSec: "00",
          breakMins: "5",
          breakSec: "00",
          displayMins: "25",
          displaySec: "00",
        };
      }

      playAndPauseHandler = () => {
        // start countdown if status = "pause" and change status to "play"
        if (this.state.status === "pause") {
          this.setState({status: "play"});

          minutes = this.state.displayMins;
          seconds = this.state.displaySec;
          timeleft = (parseInt(minutes, 10) * 60) + (parseInt(seconds, 10));
          interval = setInterval(() => countDownSecs(), 1000);

          let convertTotalSeconds = (s) => {
            min = Math.floor(s / 60);
            sec = s%60;
            if (sec < 10) {
              sec = "0"+sec;
            }
            if (min < 10) {
              min = "0"+min;
            }
            this.setState({
              displayMins: min,
              displaySec: sec
            });
            console.log(min + ":" + sec);
          }

          let countDownSecs = () => {
            counter++;
            convertTotalSeconds(timeleft-counter);

            if (counter === timeleft) {
              clearInterval(interval);
              counter = 0;
              let audio = document.getElementById('beep');
              audio.play();
              this.setState({type: "Break"});
              minutes = this.state.breakMins;
              seconds = parseInt(this.state.breakSec) + 1;
              console.log("break ", minutes + seconds);
              timeleft = (parseInt(minutes, 10) * 60) + (parseInt(seconds, 10));
              interval = setInterval(() => breakCountDown(), 1000);
            }
          }

          let breakCountDown = () => {
            counter++;
            convertTotalSeconds(timeleft-counter);
            if (counter === timeleft) {
              clearInterval(interval);
              counter = 0;
              let audio = document.getElementById('beep');
              audio.play();
              this.setState({type: "Session"});
              minutes = this.state.sessionMins;
              seconds = parseInt(this.state.sessionSec) + 1;
              timeleft = (parseInt(minutes, 10) * 60) + (parseInt(seconds, 10));
              console.log("session ", minutes + seconds);
              interval = setInterval(() => countDownSecs(), 1000);
            }
          }
        } else {
          // pause the countdown and change status to "pause"
          if (this.state.status === "play") {
            this.setState({status: "pause"})
            console.log('stop' + min + ":" + sec);
            clearInterval(interval);
            counter = 0;
          }
        }
      }

      resetHandler = () => {
        this.setState({
          type: "Session",
          status: "pause",
          sessionMins: "25",
          sessionSec: "00",
          breakMins: "5",
          breakSec: "00",
          displayMins: "25",
          displaySec: "00",
        });
        clearInterval(interval);
        counter = 0;
        let audio = document.getElementById('beep');
        audio.pause();
        audio.currentTime = 0;
      }

      breakDecrementHandler = () => {
        if (parseInt(this.state.breakMins, 10) > 1) {
          let breakDec = parseInt(this.state.breakMins, 10) - 1;
          this.setState({
            breakMins: breakDec
          });
        }
      }

      sessionDecrementHandler = () => {
        if (parseInt(this.state.sessionMins, 10) > 1 ) {
          let sessionDec = parseInt(this.state.sessionMins, 10) - 1;
          this.setState({
            sessionMins: sessionDec,
            displayMins: sessionDec
          });
        }
      }

      breakIncrementHandler = () => {
        if (parseInt(this.state.breakMins, 10) <= 59) {
          let breakInc = parseInt(this.state.breakMins, 10) + 1;
          this.setState({breakMins: breakInc});
        }
      }

      sessionIncrementHandler = () => {
        if (parseInt(this.state.sessionMins, 10) <= 59) {
          let sessionInc = parseInt(this.state.sessionMins, 10) + 1;
          this.setState({
            sessionMins: sessionInc,
            displayMins: sessionInc
          });
        }
      }

      render() {
        return (
          <div>
            <div className="container">
              <h1>Pomodoro Clock</h1>
              <div id="break">
                <h2 id="break-label">Break Length</h2>
                <p id="break-length">{this.state.breakMins}</p>
              </div>
              <div id="session">
                <h2 id="session-label">Session Length</h2>
                <p id="session-length">{this.state.sessionMins}</p>
              </div>

              <div id="inc-dec">
                <button id="break-decrement" onClick={this.breakDecrementHandler}>-1</button>
                <button id="break-increment" onClick={this.breakIncrementHandler}>+1</button>
                <button id="session-decrement" onClick={this.sessionDecrementHandler}>-1</button>
                <button id="session-increment" onClick={this.sessionIncrementHandler}>+1</button>
              </div>

              <div id="timer">
                <h2 id="timer-label">{this.state.type}</h2>
                <h3 id="time-left">{this.state.displayMins}:{this.state.displaySec}</h3>
                <button id="start_stop" onClick={this.playAndPauseHandler}>Play/Pause</button>
                <div>
                    <button id="reset" onClick={this.resetHandler}>Reset</button>
                </div>
              </div>

              <audio id="beep" src="https://s3.amazonaws.com/freecodecamp/drums/Chord_1.mp3" type="audio/mpeg"></audio>

            </div>
            <p id="copyright">&copy; 2018 Phoebe Voong-Fadel | The Coding Hamster. All rights reserved.</p>
          </div>
        );
      }
    }

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

Console