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

              
                <head>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
   <div id="root"></div>
</body>


              
            
!

CSS

              
                body {
  margin: 0;
  font-family: sans-serif;
  background-color: #e0a016;

}



.title{
  margin-left: 473px;
  margin-bottom: 0px;
  margin-top: 10px;
  padding-bottom: 0px;
  width: 30%;
  font-size: 28px;
  display: block;

}

.div-length{
  margin-left: 465px;
  padding-top: 0;
  margin-top: 0;
  width: 32%;
  font-size: 16px;
  vertical-align: top;
  
}


.break-div{
  width: 182px;
  float: left;
}

.session-div{
  width: 182px;
  float: left;
}


#break-increment{
  padding-top: 0;
  margin-top:0;
  margin-left: 30px;
  font-size: 25px;
  cursor: pointer;
}

#break-length{
  margin-top:0;
  padding-top: 0;
  margin-left: 10px;
  font-size: 25px;
  margin-right: 10px;
}

#break-decrement{
  padding-top: 0;
  margin-top:0;
   font-size: 25px;
   cursor: pointer;
}

#session-increment{
  padding-top: 0;
  margin-top: 0;
  margin-left: 30px;
  font-size: 25px;
  cursor: pointer;
}

#session-length{
  padding-top: 0;
  margin-top:0;
  margin-left: 10px;
  font-size: 25px;
  margin-right: 10px;
}

#session-decrement{
  padding-top: 0;
  margin-top:0;
  font-size: 25px;
  cursor: pointer;
}

.Timer-box{
  width: 317px;
  height: 171px;
  border-color: #a37b1c;
  border-width: 5px;
  border-style: solid;
  border-radius: 10px;
  margin-top: 150px;
  margin-left: 480px;
}

#timer-label{
  font-size: 25px;
  text-align: center;
}

.control-div{
  margin-left: 620px;
  margin-top: 20px;
}

#start_stop{
  font-size: 25px;
  cursor: pointer;
}

#reset{
  font-size: 25px;
  margin-left: 15px;
  cursor: pointer;
}

.timer-display{
  text-align: center;
  font-size: 70px;
  margin-top: 0;
}
              
            
!

JS

              
                class App extends React.Component {
  constructor(props){
    super(props);
    this.state={
      minutes: 25,
      seconds: 0,
      displayMessage: "Session",
      breakMinutes: 5,
      sessionMinutes: 25,
      sMinutes: 25,
      bMinutes: 5
    }
    //this.seconds= 0;
    //this.breakMinutes= 5;
    //this.sessionMinutes=25;
    //this.minutes= 25;
    //this.bMinutes= 5;
    //this.sMinutes= 25;
    this.timer= 0;
    this.startStopTimer= this.startStopTimer.bind(this);
    this.countDown= this.countDown.bind(this);
    this.resetTime= this.resetTime.bind(this);
    this.runningFlag= false;
    this.incBreak= this.incBreak.bind(this);
    this.decBreak= this.decBreak.bind(this);
    this.incSession= this.incSession.bind(this);
    this.decSession= this.decSession.bind(this);
    this.playAudio= this.playAudio.bind(this);
    this.pauseAudio= this.pauseAudio.bind(this);
    //this.setStateFiftyNineSec=this.setStateFiftyNineSec.bind(this);
    //this.breakFlag= false;
    //this.sessionFlag= true;
  }

  //setStateFiftyNineSec(){
    //this.setState({
      //seconds: 59
    //});
  //}
 
 playAudio(){
   var audio= document.getElementById("beep");
    audio.play();
 }

 pauseAudio(){
    var audio= document.getElementById("beep");
    audio.pause();
    audio.load();
 }

  countDown(){
    const{minutes, seconds, displayMessage} = this.state;
    //const seconds= this.seconds;
    //const minutes= this.minutes;
    //const sessionMinutes= this.sessionMinutes;
    //const breakMinutes= this.breakMinutes;
    //var bMinutes= breakMinutes;
    //var sMinutes= sessionMinutes;
    //console.log("initial sMinutes is " + sMinutes);

    if(seconds === 0){
      if(displayMessage === "Session" && minutes === 1){
        //this.minutes= 0;
        this.setState({
          minutes: 0
        });

      }else if(displayMessage === "Break"  && minutes === 1){
        //this.minutes= 0;
        this.setState({
          minutes: 0
        });
        
      }if(displayMessage === "Session" && minutes === 0){
        this.setState({
          displayMessage: "Break",
          minutes: this.state.breakMinutes,
          bMinutes: this.state.breakMinutes
        });
        this.playAudio();
        //this.minutes= breakMinutes;
        //this.bMinutes= this.state.breakMinutes;
        //this.sessionFlag= false;
        //this.breakFlag= true;
        //to start the actula countdown
        //this.setState({
         // minutes: sessionMinutes - 1,
          //seconds: 59
        //});

      }else if(displayMessage === "Break"  && minutes === 0){
        this.setState({
          displayMessage: "Session",
          minutes: this.state.sessionMinutes,
          sMinutes: this.state.sessionMinutes
        });
        this.playAudio();
        //this.minutes= sessionMinutes;
        //this.sMinutes= this.state.sessionMinutes;
        //start the actual countdown
        //this.setState({
          //minutes: breakMinutes - 1,
          //seconds: 59
        //});

      }else if(displayMessage === "Session"){
        //var modifiedMinutes= this.state.sessionMinutes - 1;
        //this.sMinutes= this.sMinutes -  1;
        //this.sMinutes= this.sMinutes -  1;
        this.setState({
          sMinutes: this.state.sMinutes - 1,
          minutes: this.state.sMinutes - 1,
          seconds: 59
        });
        //setTimeout(() => {
          //this.setStateFiftyNineSec()
        //}, 500);
        //this.seconds= 59;
        //this.minutes= this.sMinutes;
        //console.log("this.sMinutes at seconds 0 is " + this.sMinutes);
        //console.log("minutes at seconds 0 is " + minutes);

      }else if(displayMessage === "Break"){
        //this.bMinutes= this.bMinutes - 1;
        this.setState({
          bMinutes: this.state.bMinutes - 1,
          minutes: this.state.bMinutes - 1,
          seconds: 59
        });
        //setTimeout(() => {
          //this.setStateFiftyNineSec()
        //}, 500);
        //this.seconds= 59;
        //this.minutes= this.bMinutes;
      }
    }

    if(seconds > 0){
      this.setState({
        seconds: seconds - 1
      });
      //this.seconds= this.seconds - 1;
    }
  }

  startStopTimer(){
    if(!this.runningFlag){
      if(this.state.seconds >= 0){
        //console.log("pre-seconds is " + this.state.seconds);
        this.runningFlag = true;
        this.timer= setInterval(() => {
            this.countDown()
        }, 1000);
        //console.log("post-seconds is " + this.state.seconds);
        //console.log("minutes during startstopTimer is " + this.minutes);
      }

    }else if(this.runningFlag){
      clearInterval(this.timer);
      this.runningFlag = false;
    }
  }

  resetTime(){
    this.setState({
      minutes: 25,
      seconds: 0,
      displayMessage: "Session",
      breakMinutes: 5,
      sessionMinutes: 25,
      sMinutes: 25,
      bMinutes: 5
    });
    //this.seconds= 0;
    //this.breakMinutes= 5;
    //this.sessionMinutes=25;
    //this.minutes= 25;
    clearInterval(this.timer);
    this.pauseAudio();
    this.runningFlag= false;
  }

  //increment, decrement functions for break length
  incBreak(){
    if(this.state.breakMinutes < 60 && !(this.runningFlag)){
      if(this.state.displayMessage=== "Break"){
        this.setState({
          breakMinutes: this.state.breakMinutes + 1,
          minutes: this.state.breakMinutes + 1,
          bMinutes: this.state.breakMinutes + 1,
          seconds: 0
        });
        //this.seconds= 0;
        //this.breakMinutes= this.breakMinutes + 1;
        //this.minutes= this.breakMinutes;
        //this.bMinutes= this.state.breakMinutes + 1;
        //console.log("after incBreak breakMinutes is " + this.breakMinutes);
        //console.log("after decBreak tempMin is " + tempMin);
        //console.log("after incBreak minutes is"  +  this.state.minutes);
      }else if(this.state.displayMessage=== "Session"){
        this.setState({
          breakMinutes: this.state.breakMinutes + 1,
          bMinutes: this.state.breakMinutes + 1
        })
        //this.breakMinutes= this.breakMinutes + 1;
        //this.bMinutes= this.state.breakMinutes + 1;
        //console.log("after incBreak breakMinutes is " + this.state.breakMinutes);
      }
    }
  }

  decBreak(){
    if(this.state.breakMinutes > 1 && !(this.runningFlag)){
      if(this.state.displayMessage==="Break"){
        this.setState({
          breakMinutes: this.state.breakMinutes - 1,
          minutes: this.state.breakMinutes -1,
          bMinutes: this.state.breakMinutes - 1,
          seconds: 0
        });
        //this.seconds= 0;
        //this.breakMinutes= this.breakMinutes - 1;
        //this.minutes= this.breakMinutes;
        //this.bMinutes= this.state.breakMinutes - 1;
        //this.bMinutes= this.state.breakMinutes;
        //console.log("after decBreak breakMinutes is " + this.state.breakMinutes);
        //console.log("after decBreak tempMin is " + tempMin);
        //console.log("after decBreak minutes is"  +  this.state.minutes);
      }else if(this.state.displayMessage === "Session"){
        this.setState({
          breakMinutes: this.state.breakMinutes - 1,
          bMinutes: this.state.breakMinutes - 1
        })
        //this.breakMinutes= this.breakMinutes - 1;
        //this.bMinutes= this.state.breakMinutes - 1;
        //console.log("after decBreak breakMinutes is " + this.breakMinutes);
      }
    }
  }

  //increment, decrement functions for session length
  incSession(){
    if(this.state.sessionMinutes < 60 && !(this.runningFlag)){
      if(this.state.displayMessage=== "Session"){
        this.setState({
        sessionMinutes: this.state.sessionMinutes  + 1,
        minutes: this.state.sessionMinutes + 1,
        sMinutes: this.state.sessionMinutes + 1,
        seconds: 0
      });
      //this.sMinutes= this.state.sessionMinutes;
      //this.seconds= 0;
      //this.sessionMinutes= this.state.sessionMinutes + 1;
      //this.minutes= this.state.sessionMinutes + 1;
      //this.sMinutes= this.state.sessionMinutes + 1;
      //console.log("after inc, this.state.sessionMinutes is " + this.state.sessionMinutes);
      //console.log("after inc, minutes is " + this.minutes);
      }else if(!this.state.displayMessage ==="Break"){
        this.setState({
          sessionMinutes:this.state.sessionMinutes + 1,
          sMinutes: this.state.sessionMinutes + 1  
        })
        //this.sessionMinutes= this.sessionMinutes + 1;
        //this.sMinutes= this.state.sessionMinutes + 1;
      }
    }
  }

  decSession(){
   if(this.state.sessionMinutes > 1 && !(this.runningFlag)){
      if(this.state.displayMessage=== "Session"){
        this.setState({
          sessionMinutes: this.state.sessionMinutes - 1,
          minutes: this.state.sessionMinutes - 1,
          sMinutes: this.state.sessionMinutes - 1, 
          //minutes: this.state.sessionMinutes,
          seconds: 0
      });

      //this.setState({
        //minutes: this.state.sessionMinutes
      //});
      //tempMin= this.state.sessionMinutes;
      //this.seconds = 0;
      //this.sessionMinutes = this.sessionMinutes - 1;
      //this.minutes=this.sessionMinutes;
      //this.sMinutes= this.state.sessionMinutes - 1;
      //console.log("after dec, this.sessionMinutes is " + this.sessionMinutes);
      //console.log("after dec, minutes is " + this.minutes);
      //console.log("after dec, sMinutes is " + this.sMinutes);
      }else if(!this.state.displayMessage ==="Break"){
        this.setState({
          sessionMinutes: this.state.sessionMinutes - 1,
          sMinutes: this.state.sessionMinutes - 1
        })
        //this.sessionMinutes = this.sessionMinutes - 1;
        //this.sMinutes = this.state.sessionMinutes - 1;
      }
    }
  }

  render() {
    return (
      <div className="container">
        <div className= "title"><h1>25 + 5 Clock</h1></div>
        <TimerLengths  incBreak ={this.incBreak} decBreak= {this.decBreak} incSession={this.incSession} decSession={this.decSession} breakMinutes={this.state.breakMinutes}  sessionMinutes={this.state.sessionMinutes}/>
        <TimerDisplay displayMessage= {this.state.displayMessage} minutes={this.state.minutes} seconds={this.state.seconds}/>
        <TimerControls startStopTimer={this.startStopTimer} resetTime={this.resetTime}/>
        <audio id="beep" src="https://res.cloudinary.com/dqwagsh1g/video/upload/v1602008165/Beep_Pomodoro_App_enwb21.m4a" ></audio>
      </div>
    )
  }
}
//TimerLength Component
const TimerLengths = (props) => {
    
    return (
        <div className="div-length">
            <div className="break-div">
                <h2 className="header2Break" id="break-label">Break Length</h2>
                <i className="fa fa-arrow-up" id="break-increment" onClick={props.incBreak}></i>
                <span id="break-length">{props.breakMinutes}</span>
                <i className="fa fa-arrow-down" id="break-decrement" onClick={props.decBreak}></i>
            </div>
            <div className="session-div">
                <h2 className="header2Session" id="session-label">Session Length</h2>
                <i className="fa fa-arrow-up" id="session-increment" onClick={props.incSession}></i>
                <span id="session-length">{props.sessionMinutes}</span>
                <i className="fa fa-arrow-down" id="session-decrement" onClick={props.decSession} ></i>
            </div>
        </div>
    )
}

//TimerDisplay Component
const TimerDisplay = (props) => {
    return (
        <div className="Timer-box">
            <h2 id="timer-label">{props.displayMessage}</h2>
            <h2 className="timer-display" id="time-left">{props.minutes < 10 ? `0${props.minutes}` : props.minutes}:{props.seconds < 10 ? `0${props.seconds}` : props.seconds}</h2>
        </div>
    )
}

// TimerControls Component
const TimerControls = (props) => {
    return (
        <div className= "control-div">
            <span ><i class="fa fa-play"  onClick={props.startStopTimer} id="start_stop"></i><i class="fa fa-pause"  onClick={props.startStopTimer}  id="start_stop"></i></span>
            <i className="fa fa-refresh"  id="reset" onClick= {props.resetTime}></i>
        </div>
    )
}




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

              
            
!
999px

Console