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

              
                
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      content="Project : Build a 25 + 5 Clock for freecodecamp"
    />
    
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
    <link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Teko:wght@700&display=swap" rel="stylesheet">

    <title>A 25 + 5 Clock</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id='container'></div>
    
  </body>
</html>


              
            
!

CSS

              
                $back-color: #160203;

$gold:#ECB939;
$dark-grey:#88888A;
$dark-maroon:#130109;
$dark-mauve: #886072;

$font-size-med: 1.4em;
$font-weight-lrg: 700;

html{
  height: 100vh;
}
html,body {
  min-height: 100vh;
  background-color: $back-color;
}
.container {
  display: flex;
  position: relative;
  flex-direction: row;
  left: 20%;
  font-size: 1.8em;
  color: #fff;
  text-shadow: 0 0 8px #fff, 0 0 8px #fff, 0 0 15px #F0E6E7, 0 0 2px #ECB939 ;
 
}

.ui{
   padding: 0.8em;
   margin-right:15px;
   margin-top: 25px;
   font-family: 'Teko', sans-serif;
   font-size: 0.8em;
   border-radius: 15px;
}
.text{
   margin-right:35px;
   
}
#time-left{
   background-color:$dark-grey;
   color:$dark-maroon;
   font-size: $font-size-med;
   font-weight:$font-weight-lrg;
   
}
button:hover{
   box-shadow: 4px 4px 5px $gold;
}

[id^=break-],[id^=session-]{
   width: 18%;
}
#timer-label{
   border-left: 5px groove $dark-mauve;
   border-right:5px groove $dark-mauve;
}
              
            
!

JS

              
                class App extends React.Component {
   constructor(props){
     super(props);
     this.state={
       timerId:'',
       paused: false,
       timerMM : 25,
       timerSS:0,
       setBreak: false,
       setSession: true,
       defaultBreak: 5,
       defaultSession: 25,
       audioId:"",
     }
     this.startPlay = this.startPlay.bind(this);
     this.timer  = this.timer.bind(this);
     this.clear = this.clear.bind(this);
     this.reset = this.reset.bind(this);
     this.playAudio= this.playAudio.bind(this);
    }
  
playAudio(shouldPause){
   this.audioId = document.getElementById("beep");
   this.audioId.play();
   if(shouldPause){
       this.audioId.pause();
       this.audioId.currentTime=0;
   } 
       
}
  
handleIncBreak(){
   if(this.state.defaultBreak<60) {
      this.setState({defaultBreak: ++this.state.defaultBreak});
   }
 }
 handleDecBreak(){
   if(this.state.defaultBreak>=2) {
     this.setState({defaultBreak: --this.state.defaultBreak});
   }
 }
 handleIncSession(){
   if(this.state.defaultSession<60) {
     this.setState({defaultSession: ++this.state.defaultSession,timerMM: this.state.defaultSession});
   }
 }
handleDecSession(){
   if(this.state.defaultSession>=2) {
     this.setState({defaultSession: --this.state.defaultSession,timerMM: this.state.defaultSession});
   }
 }
 componentDidMount(){
    this.render();
 }
 reset(){
   //stop the timer
   this.clear();
   const PAUSEAUDIO=true;
   this.playAudio(PAUSEAUDIO);
   //reset the values
   this.setState({
                 timerId:'',
                 paused: false,
                 timerMM : 25,
                 timerSS:0,
                 setBreak: false,
                 setSession: true,
                 defaultBreak: 5,
                 defaultSession: 25,
                 audioId:""
    });
 }
  
timer(){
      const SHOULDSTOP = false;
      if((this.state.timerSS===0)&&((this.state.timerMM ===0))){
           
           if(this.state.setSession){
              //is the end of a session, set setBreak to true, setSession to false
               
               this.setState({setBreak: true,
                                       setSession: false,
                                       timerMM:this.state.defaultBreak,});   
           } else {
              //is the end of a break, set setSession to true, setBreak to false
               
               this.setState({setBreak: false,
                                       setSession: true,
                                       timerMM:this.state.defaultSession });      
           }
           this.playAudio(SHOULDSTOP);
           
      }
      else if((this.state.timerSS) ===0 ){
          
          this.setState({timerMM: --this.state.timerMM,
                        timerSS : 59});  
        
      } else if(this.state.timerSS!==0 ){
          this.setState({timerSS: --this.state.timerSS,
                                  }); 
         
     }
     
 } 
  
 clear(){
     window.clearTimeout(this.state.timerId);
  }
  
startPlay(){
         
         if(!this.state.paused ){
        
           this.state.timerId = window.setInterval(()=>this.timer(), 1000);
        
         } else { 
           
           this.clear();
         } 
         
         this.setState({paused:!this.state.paused})
   }
'use strict';
render(){
        let styleBreak =''; let text='';
        if(this.state.timerMM===0 && this.state.timerSS===0){
          styleBreak = {'border':'4px solid gold','transform': 'scale(1.1,1.2)'};
          const PAUSEAUDIO= false;
          this.playAudio( PAUSEAUDIO);
        } else {
          styleBreak = {'border':'none'};
        }
        return(
             <div className="container">
                <fallbackComponent/>
                <div id="break-label">
                  <button type="button"  onClick={()=>this.handleDecBreak()}id="break-decrement"> <span class="fa fa-minus" aria-hidden="true"></span> </button>
                  <div class="text" >   Break Length </div>
                  <div id="break-length">{this.state.defaultBreak} </div>
                  <button onClick={()=>this.handleIncBreak()} id="break-increment"> <span class="fa fa-plus" aria-hidden="true"></span>  </button>
                </div>
                
                <div id="session-label">
                  <button onClick={()=>this.handleDecSession()} id="session-decrement"> <span class="fa fa-minus" aria-hidden="true"></span> </button>
                  <div class="text" >    Session Length </div>
                  <div id="session-length">{this.state.defaultSession} </div>
                  <button onClick={()=>this.handleIncSession()}  id="session-increment"> <span class="fa fa-plus" aria-hidden="true"></span>  </button>
                </div>
                <div id="timer-label">
                  {this.state.setSession?"Session":"Break"}
                  <div style={styleBreak} id="time-left">
                   {this.state.timerMM<10?'0'+this.state.timerMM:this.state.timerMM}:{this.state.timerSS<10?'0'+this.state.timerSS:this.state.timerSS}
                   
                  </div>
                  <button class="ui primary button" onClick={this.startPlay} id="start_stop">
                    start/pause
                  </button>
                  <button class="ui secondary button" onClick={this.reset} id="reset">
                    reset
                  </button>
                  
                </div>
                <audio
                    id="beep"
                    preload="auto"
                    src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/audio/BeepSound.wav"
                 />
             </div>
        );
    
   }
}


const fallbackComponent =({error, componentStack, resetErrorBoundary}) => {
  return (
          <div>
          <div>{error.message}</div>
          <button onClick={resetErrorBoundary}>Try again</button>
          </div>
         );
  
};

class AppWrapper extends React.Component {
  constructor(props){
    super(props);
  }
  render() {
    return (
      <ErrorBoundary fallbackComponent={fallbackComponent}>
      <App/>
      </ErrorBoundary>
    );
  }
};


class ErrorBoundary extends React.Component {
  constructor(props) {
    super(props);
    this.state = { 
      hasError: false ,
    };
  }
  static getDerivedStateFromError(error) {
    // Update state so the next render will show the fallback UI.
    return { hasError: true };
  }
  render() {
       if (this.state.hasError) {
         <fallbackComponent/>
       } 
       return this.props.children;
  }
}

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

Console