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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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

              
                <!DOCTYPE html>
<html lang="en">

<head>
    <link rel="stylesheet" href="style.css">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js" defer></script>
</head>

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

</html>
              
            
!

CSS

              
                *,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  background-color: #b71c1c;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  outline: 0;
}

#container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  flex-direction: column;
}

#clock {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  width: 450px;
  min-height: 650px;
  border-radius: 16px;
  border-radius: 26px;
  background: linear-gradient(145deg, #c41e1e, #a51919);
  box-shadow: 5px 5px 10px #a31919, -5px -5px 10px #cb1f1f;
}

#container h4 {
  color: #b71c1c;
  margin-bottom: 20px;
  font-weight: 600;
}

#buttons {
  display: flex;
  flex-direction: row;
  color: #f3e5f5;
}

#timer-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #f3e5f5;
  width: 350px;
  height: 350px;
  border-radius: 50%;
  background: linear-gradient(-145deg, #c41e1e, #a51919);
  box-shadow: 5px 5px 9px #a71919, -5px -5px 9px #c71f1f;
}

#break-label {
  display: flex;
  flex-direction: column;
  margin: 20px;
}

#break {
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  font-size: 30px;
  font-weight: 600;
  align-items: center;
}

#session-label {
  display: flex;
  flex-direction: column;
  margin: 20px;
}

#session {
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  font-size: 30px;
  align-items: center;
  font-weight: 600;
}

#time-left {
  font-size: 90px;
  font-weight: 700;
}

#start_stop {
  font-size: 50px;
  cursor: pointer;
  border-radius: 50%;
  background: linear-gradient(-145deg, #c41e1e, #a51919);
  box-shadow: 6px 6px 11px #9d1818, -6px -6px 11px #d12020;
  margin-right: 10px;
}

#reset {
  font-size: 50px;
  cursor: pointer;
  border-radius: 50%;
  background: linear-gradient(-145deg, #c41e1e, #a51919);
  box-shadow: 6px 6px 11px #9d1818, -6px -6px 11px #d12020;
  margin-left: 10px;
}

#break-increment {
  cursor: pointer;
}

#break-decrement {
  cursor: pointer;
}

#session-increment {
  cursor: pointer;
}

#session-decrement {
  cursor: pointer;
}

#title {
  margin: 40px;
  min-width: 85%;
  height: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 6px;
  background-color: #ef5350;
}

              
            
!

JS

              
                let countDown;
class PomodoroClock extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      breakTime: 5,
      sessionTime: 25,
      sessionMinutes: 25,
      sessionSeconds: "00",
      timerIsOn: false,
      pause: false,
      session: "Session",
    };
  }

  //increment Break Time
  incrementBreakTime = () => {
    if (this.state.breakTime < 60 && this.state.timerIsOn === false) {
      this.setState({
        breakTime: this.state.breakTime + 1,
      });
    }
  };

  //Decrement Break Time
  decrementBreakTime = () => {
    if (this.state.breakTime > 1 && this.state.timerIsOn === false) {
      this.setState({
        breakTime: this.state.breakTime - 1,
      });
    }
  };

  //Increment Session's Time
  incrementSession = () => {
    if (
      this.state.sessionTime < 60 &&
      this.state.timerIsOn === false &&
      this.state.sessionTime < 9
    ) {
      this.setState({
        sessionTime: this.state.sessionTime + 1,
        sessionMinutes: "0" + (parseInt(this.state.sessionTime) + 1),
        sessionSeconds: "00",
      });
    } else if (
      this.state.sessionTime < 60 &&
      this.state.timerIsOn === false &&
      parseInt(this.state.sessionTime) >= 9
    ) {
      this.setState({
        sessionTime: this.state.sessionTime + 1,
        sessionMinutes: parseInt(this.state.sessionTime) + 1,
        sessionSeconds: "00",
      });
    }
  };

  //Decrement Session's Time
  decrementSession = () => {
    if (
      this.state.sessionTime > 1 &&
      this.state.sessionTime > 10 &&
      this.state.timerIsOn === false
    ) {
      this.setState({
        sessionTime: this.state.sessionTime - 1,
        sessionMinutes: this.state.sessionMinutes - 1,
        sessionSeconds: "00",
      });
    } else if (this.state.sessionTime > 1 && this.state.sessionTime <= 10) {
      this.setState({
        sessionTime: this.state.sessionTime - 1,
        sessionMinutes: "0" + (this.state.sessionMinutes - 1),
        sessionSeconds: "00",
      });
    }
  };

  //Start/Stop Timer
  timer = () => {
    if (this.state.timerIsOn === false) {
      this.setState({
        timerIsOn: true
      })
      let seconds =
      this.state.sessionMinutes * 60 + parseInt(this.state.sessionSeconds);
      
      const now = Date.now();
      const then = now + seconds * 1000;
      
      countDown = setInterval(() => {
        const secondsLeft = Math.round((then - Date.now()) / 1000);
        if(this.state.sessionMinutes === "00" && this.state.sessionSeconds === "00") {
          document.getElementById("beep").play();
        }
        // check if we should stop it!
        if (secondsLeft < 0) {
          clearInterval(countDown);
          this.break();
          return;
        }
        //display it
        this.displayTimeLeft(secondsLeft);
      }, 1000);
    } else {
      clearInterval(countDown);
      let minuteToPause = this.state.sessionMinutes;
      let secondsToPause = this.state.sessionSeconds;
      this.setState({
        timerIsOn: false,
        sessionMinutes: minuteToPause,
        sessionSeconds: secondsToPause,
      });
    }
  };

  //Display the timer
  displayTimeLeft = (seconds) => {
    const minutes = Math.floor(seconds / 60);
    const remainderSeconds = seconds % 60;
    if (remainderSeconds >= 10 && minutes >= 10) {
      this.setState({
        sessionMinutes: minutes,
        sessionSeconds: remainderSeconds,
      });
    } else if (remainderSeconds <= 9) {
      this.setState({
        sessionMinutes: "0" + minutes,
        sessionSeconds: "0" + remainderSeconds,
      });
    } else {
      this.setState({
        sessionMinutes: "0" + minutes,
        sessionSeconds: remainderSeconds,
      });
    }
  };

  //Check if time is over and the break can start
  break = () => {
    if(this.state.pause === false) {
      if(this.state.breakTime > 9){
    this.setState({
      session: "Break",
      sessionMinutes: this.state.breakTime,
      sessionSeconds: "00",
      timerIsOn: false,
      pause: true
    })
    this.timer()
  } else {
       this.setState({
         session: "Break",
         sessionMinutes: "0" + this.state.breakTime,
         sessionSeconds: "00",
         timerIsOn: false,
         pause: true,
       });
       this.timer();
  }
  } else {
    if(this.state.sessionTime > 9) {
    this.setState({
      session: "Session",
      sessionMinutes: this.state.sessionTime,
      sessionSeconds: "00",
      timerIsOn: false,
      pause: false,
    });
    this.timer();
  } else {
    this.setState({
      session: "Session",
      sessionMinutes: "0" +this.state.sessionTime,
      sessionSeconds: "00",
      timerIsOn: false,
      pause: false,
    });
    this.timer();
  }
}
  };

  //Reset Time
  resetTime = () => {
    clearInterval(countDown);
    this.setState({
      session: "Session",
      breakTime: 5,
      sessionTime: 25,
      sessionMinutes: 25,
      sessionSeconds: "00",
      timerIsOn: false,
      pause: false,
    });
    document.getElementById("beep").currentTime = 0;
    document.getElementById("beep").pause();
  };

  render() {
    return (
      <div id="container">
        <div id="clock">
          <div id="title">
            <h4>POMODORO CLOCK</h4>
          </div>
          <div id="buttons">
            <div id="break-label">
              BREAK LENGTH
              <div id="break">
                <div
                  id="break-decrement"
                  className="material-icons"
                  onClick={() => this.decrementBreakTime()}
                >
                  remove_circle
                </div>
                <div id="break-length">{this.state.breakTime}</div>
                <div
                  id="break-increment"
                  className="material-icons"
                  onClick={() => this.incrementBreakTime()}
                >
                  add_circle
                </div>
              </div>
            </div>
            <div id="session-label">
              SESSION LENGTH
              <div id="session">
                <div
                  id="session-decrement"
                  className="material-icons"
                  onClick={() => this.decrementSession()}
                >
                  remove_circle
                </div>
                <div id="session-length">{this.state.sessionTime}</div>
                <div
                  id="session-increment"
                  className="material-icons"
                  onClick={() => this.incrementSession()}
                >
                  add_circle
                </div>
              </div>
            </div>
          </div>
          <div id="timer-label">
            <h3>{this.state.session}</h3>
            <div id="time-left">
              <audio id="beep" src="https://www.pacdv.com/sounds/interface_sound_effects/sound10.mp3" type="audio/mp3"></audio>
              {this.state.sessionMinutes}:{this.state.sessionSeconds}
            </div>
            <div id="button-timer">
              <div
                id="start_stop"
                className="material-icons"
                onClick={() => this.timer()}
              >
                play_circle_filled
              </div>
              <div
                id="reset"
                className="material-icons"
                onClick={() => this.resetTime()}
              >
                replay
              </div>
            </div>
          </div>
        </div>
      </div>
    );
  }
}

ReactDOM.render(<PomodoroClock />, document.getElementById("root"));
//ReactDOM.render(<PomodoroClock />, document.getElementById("root"));

              
            
!
999px

Console