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

              
                <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">

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

Hello Camper!

For now, the test suite only works in Chrome! 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

              
                @import url('https://fonts.googleapis.com/css?family=Major+Mono+Display');

body {
  color: #8b0000;
  font-family: 'Major Mono Display', monospace;
}

#root {
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
}

#clock {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-gap: 1em;
}
#title {
  grid-column: 1 / 4;
  text-align: center;
  font-size: 3.5em;
}
#explanation {
  grid-column: 1 / 4;
  font-family: sans;
  background-color: pink;
  background-image: url("https://upload.wikimedia.org/wikipedia/commons/9/9a/Tomato_slices.jpg");
  background-repeat: repeat;
  background-size: auto;
}

div.transbox {
  background-color: #ffffff;
  margin: 2em;
  opacity: 0.7;
  filter: alpha(opacity=60); /* For IE8 and earlier */
}

div.transbox h2 {
  margin: 5%;
  padding: 5%;
  font-weight: bold;
  color: #000000;
}

.fancyFont {
  font-family: 'Major Mono Display', monospace;
}

#controlStation {
  grid-column: 1 / 2;
  background-color: #d2e8ba;
}

#session-box, #break-box {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
}

#session-label, #break-label {
 background-color: #9acc65;
 padding: 0.25em;
 grid-column: 1 / 4;
 margin-top: 1em;
}

#session-decrement, #break-decrement {
 grid-column: 1 / 2;
}

#session-length, #break-length {
  grid-column: 2 / 3;
  font-size: 1.25em;
}

#session-increment, #break-increment {
  grid-column: 3 / 4;
}


#timerStation {
  grid-column: 2 / 3;
  background-color: #ec543c;
  color: black;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

#time-left {
  background-color: white;
  border: 2px solid black;
  margin: 1em;
  border-radius: 2px;
  font-size: 2em;
  grid-column: 1 / 3;
}

#timer-label {
  grid-column: 1 / 3;
  margin-top: 2em;
}

#start_stop {
  grid-column: 1 / 2;
}

#reset {
  grid-column: 2 / 3;
}

#pomodoro-photo {
  grid-column: 3 / 4;
  background-color: #d2e8ba;
}

#pomodoro-photo img {
  max-width: 100%;
  max-height: 100%;
}

#footer {
  grid-column: 1 / 4;
  text-align: right;
  font-family: sans;
  font-size: 0.5em;
}

#photo-copyright {
  text-align: right;
}

#copyright {
  text-align: center;
}

button {
  font-size: 2em;
  margin: 0.5em;
  padding: 0.25em 0.35em;
}

button:hover {
  color: #da614e;
}

button:active {
  transform: translateY(4px);
}

              
            
!

JS

              
                class PomodoroClock extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      sessionLength: 25,
      breakLength: 5,
      currentTime: (new Date()).toLocaleString(),
      minutesLeft: 25,
      secondsLeft: 0,
      toggleType: "Session",
      togglePlay: false,
      firstTime: true
      
    }
    this.launchClock();
    this.launchTimer();
    
    this.handleClickSessionIncrement = this.handleClickSessionIncrement.bind(this);
    this.handleClickSessionDecrement = this.handleClickSessionDecrement.bind(this);
    this.handleClickBreakIncrement = this.handleClickBreakIncrement.bind(this);
    this.handleClickBreakDecrement = this.handleClickBreakDecrement.bind(this);
    this.handleClickPlayPause =
      this.handleClickPlayPause.bind(this);
    this.handleClickReset = this.handleClickReset.bind(this);
    this.launchClock = this.launchClock.bind(this);
    this.launchTimer = this.launchTimer.bind(this);
    this.formatTimer = this.formatTimer.bind(this);
  }
  
  handleClickSessionIncrement() {
    let newSessionLength = this.state.sessionLength + 1;
    if (newSessionLength > 0 && newSessionLength < 61) {
      this.setState( {
        sessionLength: newSessionLength
      });
    }
  }
  
  handleClickSessionDecrement() {
    let newSessionLength = this.state.sessionLength - 1;
    if (newSessionLength > 0 && newSessionLength < 61) {
      this.setState( {
        sessionLength: newSessionLength
      });
    }
  }
  
  handleClickBreakIncrement() {
    let newBreakLength = this.state.breakLength + 1;
    if (newBreakLength > 0 && newBreakLength < 61) {
      this.setState( {
        breakLength: newBreakLength
      });
    }
  }
  
  handleClickBreakDecrement() {
    let newBreakLength = this.state.breakLength - 1;
    if (newBreakLength > 0 && newBreakLength < 61) {
      this.setState( {
        breakLength: newBreakLength
      });
    }
  }
  
  handleClickPlayPause() {
    if (this.state.firstTime) {
      let newMinutes = this.state.sessionLength;
        this.setState({
          firstTime: false,
          minutesLeft: newMinutes
        })
      }
    if (this.state.togglePlay) {
      //console.log("timer go!");
      this.setState( {
        togglePlay: false
      });
    } else {
      //console.log("timer pause!");
      this.setState( {
        togglePlay: true
      })
    }
  }
  
  handleClickReset() {
    let beep = document.getElementById('beep');
    beep.currentTime = 0;
    let newMinutes = this.state.sessionLength;
    this.setState( {
      minutesLeft: newMinutes,
      secondsLeft: 0,
      toggleType: "Session",
      togglePlay: false
    })
  }
  
  launchClock() {
    setInterval(()=>{
      //console.log('Updating time...')
      this.setState({
        currentTime: (new Date()).toLocaleString() 
      })
    }, 1000)      
  }
  
  launchTimer() {
      setInterval(()=> {
        //console.log("Updating timer...")
        if (this.state.togglePlay) {
          let minutes = this.state.minutesLeft;
          let seconds = this.state.secondsLeft;
          let newMinutes = 0;
          
          if (minutes == 0 && seconds == 0 && this.state.toggleType == "Session") {
            let audioElement = document.getElementById('beep');
    audioElement.play();
            newMinutes = this.state.breakLength;
            //console.log("Time to switch to Break with ", newMinutes, " minutes");
            minutes = newMinutes;
            this.setState( {
              minutesLeft: newMinutes,
              secondsLeft: 0,
              toggleType: "Break"
            })
          } else if (minutes == 0 && seconds == 0 && this.state.toggleType == "Break") {
            let audioElement = document.getElementById('beep');
    audioElement.play();
            newMinutes = this.state.sessionLength;
            //console.log("Time to switch to Session with ", newMinutes, " minutes");
            minutes = newMinutes;
            this.setState( {
              minutesLeft: newMinutes,
              secondsLeft: 0,
              toggleType: "Session"
            })
          }
          
          if (seconds <= 0) {
            minutes--;
            seconds = 59;
          } else {
            seconds--;  
          }
          this.setState({
            minutesLeft: minutes,
            secondsLeft: seconds
          })
        }
      }, 1000)
  }
  
  formatTimer() {
    let minutes = this.state.minutesLeft.toString();
    let seconds = this.state.secondsLeft.toString();
    if (minutes < 10) {minutes = "0"+minutes;}
    if (seconds < 10) {seconds = "0"+seconds;}
    //console.log(minutes+ ':' +seconds);
    return minutes+':'+seconds;
  }
  
  render() {
    return (
    <div id="clock">
        <h1 id="title"> Pomodoro Clock <i className="fas fa-stopwatch"></i></h1>
        
        <div id="explanation">
          <div className="transbox">
            <h2>The <span className="fancyFont">Pomodoro Technique</span> allows you to focus on your task on hand for a chunk of time, and then take a break. Repeat. This process helps with <span className="fancyFont">concentration</span>, <span className="fancyFont">retention</span> and <span className="fancyFont">anxiety</span>.</h2>
          </div>
        </div>
        <div id="controlStation">
          <div id="session-box">
            <div id="session-label"><h3>Session Length <i className="fas fa-hourglass-start"></i></h3></div>
            <div id="session-decrement"><button onClick={this.handleClickSessionDecrement}><i className="fas fa-arrow-circle-down"></i></button></div>
            <div id="session-length"><h2>{this.state.sessionLength}</h2></div>
            <div id="session-increment"><button onClick={this.handleClickSessionIncrement}><i className="fas fa-arrow-circle-up"></i></button> </div>
          </div>
          
          <div id="break-box">
            <div id="break-label"><h3>Break Length <i className="fas fa-hourglass-end"></i></h3></div>
            <div id="break-decrement"><button onClick={this.handleClickBreakDecrement}><i className="fas fa-arrow-circle-down"></i></button></div>
            <div id="break-length"><h2>{this.state.breakLength}</h2></div>
            <div id="break-increment"><button onClick={this.handleClickBreakIncrement}><i className="fas fa-arrow-circle-up"></i></button></div>
          </div>
          
        </div>
        
        <div id="timerStation">
          <div id="timer-label"><h2>{this.state.toggleType == "Session" ? "Session" : "Break"}</h2></div>
          <div id="time-left"><h1>{this.formatTimer()}</h1></div>
          <div id="beep-area"><audio id="beep"><source src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/742140/C.mp3' type="audio/mpeg"></source></audio></div>
          <div id="start_stop"><button onClick={this.handleClickPlayPause}><i className="fas fa-play-circle"></i><i className="fas fa-pause-circle"></i></button></div>
          <div id="reset"><button onClick={this.handleClickReset}><i className="fas fa-redo"></i></button></div>
        </div> 
        
        <div id="pomodoro-photo">
          <a title="The original uploader was Erato at Italian Wikinews. [CC BY-SA 2.5 (https://creativecommons.org/licenses/by-sa/2.5)], via Wikimedia Commons" href="https://commons.wikimedia.org/wiki/File:Il_pomodoro.jpg"><img alt="Il pomodoro" src="https://upload.wikimedia.org/wikipedia/commons/3/34/Il_pomodoro.jpg"/></a>
          <h3>{this.state.currentTime}</h3>
        </div>
        
        <div id="footer">
          <p id="copyright">&copy; 2019 Heather Nuffer</p>
          <p><a id="photo-copyright" title="Scott Bauer, USDA ARS [Public domain], via Wikimedia Commons" href="https://commons.wikimedia.org/wiki/File:Tomato_slices.jpg" target="_blank">Tomato Slices Photo Info</a></p>
          
        </div>
      </div>)
    
  }
}



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



// !! 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