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 lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
  </head>
  <body>
    <div id="container"></div>
    <audio id="beep" src="http://www.peter-weinberg.com/files/1014/8073/6015/BeepSound.wav"></audio>
  </body>
</html>
              
            
!

CSS

              
                body{
  background-color: #026873;
  background-image: linear-gradient(90deg, rgba(255,255,255,.07) 50%, transparent 50%),
  linear-gradient(90deg, rgba(255,255,255,.13) 50%, transparent 50%),
  linear-gradient(90deg, transparent 50%, rgba(255,255,255,.17) 50%),
  linear-gradient(90deg, transparent 50%, rgba(255,255,255,.19) 50%);
  background-size: 13px, 29px, 37px, 53px;
}

#container{
  background-color: white;
  margin: 10vw;
  padding: 5vw;
  min-height: 100px;
  min-width: 100px;
  border: 2vw outset #40b8e8;
  border-radius: 5px;
}

#react-container{
  display: flex;
  justify-content: space-evenly;
}

#timer-label{
  padding: 6vw;
}

#break-label,#session-label{
  display: flex;
  justify-content: center;
  align-items: center;
}

#break-label button,#session-label button{
  max-height: 30px;
  margin: 0px 10px;
  border-radius: 5px;
}
              
            
!

JS

              
                /*
Could add:
- Add a clock animation instead of the word "Timer".
*/


//Audio element to play and stop.
let audio = document.getElementById("beep");


class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      session: 25,
      break: 5,
      timer: [0, 0],
      on: false,
      resume: false,
      mode: "Session"
    };
    this.activate = this.activate.bind(this);
    this.reset = this.reset.bind(this);
    this.breakValue = this.breakValue.bind(this);
    this.sessionValue = this.sessionValue.bind(this);
  }

  activate() {
    if (this.state.on == false) {
      if (this.state.resume == false) {
        this.setState({
          on: true,
          resume: true,
          timer: [this.state.session, 0],
          tick: setInterval(() => {
            let actualTimer = this.state.timer;
            if (actualTimer[1] != 0) {
              this.setState({
                timer: [actualTimer[0], actualTimer[1] - 1]
              });
            } else if (actualTimer[0] != 0) {
              this.setState({
                timer: [actualTimer[0] - 1, 59]
              });
            } else {
              if(this.state.mode=="Session"){
                audio.currentTime = 0;
                audio.play();
                this.setState({
                  timer:[this.state.break,0],
                  mode: "Break"
                });
              }else{
                audio.currentTime = 0;
                audio.play();
                this.setState({
                  timer:[this.state.session,0],
                  mode: "Session"
                });
              }
              
            }
          }, 1000)
        });
      } else {
        audio.currentTime = 0;
        audio.play();
        this.setState({
          on: true,
          tick: setInterval(() => {
            let actualTimer = this.state.timer;
            if (actualTimer[1] != 0) {
              this.setState({
                timer: [actualTimer[0], actualTimer[1] - 1]
              });
            } else if (actualTimer[0] != 0) {
              this.setState({
                timer: [actualTimer[0] - 1, 59]
              });
            } else {
              if(this.state.mode=="Session"){
                this.setState({
                  timer:[this.state.break,0],
                  mode: "Break"
                });
              }else{
                this.setState({
                  timer:[this.state.session,0],
                  mode: "Session"
                });
              }
              
            }
          }, 1000)
        });
      }
    } else {
      this.setState({ on: false });
      clearInterval(this.state.tick);
    }
  }

  reset() {
    this.setState({
      session: 25,
      break: 5,
      timer: [0, 0],
      on: false,
      resume: false,
      mode: "Session"
    });    
    clearTimeout(this.state.tick);
    audio.pause();
    audio.currentTime = 0;
  }

  breakValue(value) {
    let newBreak = this.state.break;
    if ((newBreak == 1 && value == -1) || (newBreak == 60 && value == 1)) {
    } else {
      this.setState({
        break: newBreak + value,
        resume: false
      });
    }
  }

  sessionValue(value) {
    let newSession = this.state.session;
    if ((newSession == 1 && value == -1) || (newSession == 60 && value == 1)) {
    } else {
      this.setState({
        session: newSession + value,
        resume: false
      });
    }
  }

  render() {
    return (
      <div id="react-container">
        <div id="timer-label">
          {this.state.mode=="Session" ? <p>Timer</p> : <p>Break-time</p>}
          <br />
          <div id="time-left">
            <center>
              {this.state.timer[0] <= 9 && 0}
              {this.state.timer[0]}:{this.state.timer[1] <= 9 && 0}
              {this.state.timer[1]}
            </center>
          </div>
        </div>
        <div>
          <center>Session</center>
          <div id="session-label">
            <button
              id="session-decrement"
              onClick={() => this.sessionValue(-1)}
            >
              -
            </button>
            <p id="session-length">{this.state.session}</p>
            <button id="session-increment" onClick={() => this.sessionValue(1)}>
              +
            </button>
          </div>
          <center>Break</center>
          <div id="break-label">
            <button id="break-decrement" onClick={() => this.breakValue(-1)}>
              -
            </button>
            <p id="break-length">{this.state.break}</p>
            <button id="break-increment" onClick={() => this.breakValue(1)}>
              +
            </button>
          </div>
          <br />
          <center>
            <button id="start_stop" onClick={() => this.activate()}>
              Start
            </button>
            <button id="reset" onClick={() => this.reset()}>
              Reset
            </button>
          </center>
        </div>
      </div>
    );
  }
}

ReactDOM.render(<App />, document.getElementById("container"));

              
            
!
999px

Console