123

Pen Settings

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <Body>
  <div class="container-fluid">
    <div class="row">
      <h1> POMODOROMANIA</H1>
    </div>
    <div class="row"> 
      <div class="col-xs-12 col-md-6 bub">
        <h3> Work </h3>
        <p id="work">
          <button id="workPlus" class="btn timeChange" val='+w'>+</button> 
          <span id="workDisplay"></span> 
          <button id="workMinus" class="btn timeChange" val='-w'>-    </button>
        </p>
      </div>
      
      <div class="col-xs-12 col-md-6 bub">
        <h3> Break </h3>
        <p id="break">
          <button id="breakPlus" class="btn timeChange" val='+b'>+</button> 
          <span id="breakDisplay">
          </span>
          <button id="breakMinus" class="btn timeChange" val='-b'>-</button>
        </p>
      </div>
    </div>
    <div class='row'>
      <div class='col-xs-2 col-md-4'></div>
      <div  id= 'timerdiv' class="col-xs-8 col-md-4">
        <h3> Timer </h3>
        <p id="timer">
          <button id="timerGo"class="btn" >
            GO
          </button>
          <span id="timerDisplay">
          </span>
        </p>
       
        <p>GET TO WORK</p> 
         <p> <button id="reset"class="btn" >
            reset
          </button>
        </p>
        
      </div>
    </div>
</body>

            
          
!
            
              h1,h3,p{
  text-align:center;
}
body{
  background-color: #faa6ff;
  oolor: red;
  font-family: 'Pacifico', cursive;
}

#timerdiv{
  background-color: #7353ba;
  Border-radius: 1000px;
}

.bub{
  
}
h1{
  color: #0f1020;
}
h3{
  color: #0f1020;
}
p {
  color: #0f1020;
}

#reset{
  text-align:center;
}
            
          
!
            
              /*to do
4c. create alert and play a sound.
*/
//base timer object
var timerOb={
  'work': 25,
  'break':5,
};
//sound 

  var sound= new Audio('https://s3.amazonaws.com/freecodecamp/simonSound3.mp3');
//global that will be assigned to the interval function
var int='';
//function to input times in p tags (will trigger on ready and when setup values change)
function update(){
  //update work span
  $("#workDisplay")[0].innerHTML=timerOb.work+':00';
  //update break span
  $("#breakDisplay")  [0].innerHTML=timerOb.break+':00';
  //update timer span
  $("#timerDisplay")[0].innerHTML=timerOb.work+':00';
  
}
$( document ).ready(update());
//listener function on + and Minus butons

$('.timeChange').click(function(event){
  //determine what button got pressed and then update the UI with new values
  var val = event.target.attributes.val.value;
  if (val=='+w'){
    timerOb.work++;
  }
  if (val=='-w'){
    //prevent negative values
    if(timerOb.work!=0){
      timerOb.work--;
    }
  }
  if (val=='+b'){
    timerOb.break++;
  }
  if (val=='-b'){
    //prevent negative values
    if(timerOb.break!=0){
      timerOb.break--;
    }
  }
  update();
});
//click listener on GO
$('#timerGo').click(function(){
  //setup
  var timerMin=timerOb.work;
  var timerSec=':00';
  var onBreak=false;
  //begin Work countdown
  int= window.setInterval(function(){
    //normal case for non zero seconds
    if (timerSec!=':00'){
        //get the  number of seconds
      var tmp=Number(timerSec.substr(1,2));
        //subtract one and put it back into a string
      tmp--;
      tmp=String(tmp);
        //if there's only one digit, tack on a zero
        if(tmp.length==1){
          tmp='0'+tmp;
        }
      //put the seconds back together
      timerSec=':'+(String(tmp));      
    }
    //case if seconds are in zeroes, set the seconds to 59 and remove a minute
    else{
      //case if the timer has hit zero minutes, zero seconds
      if(timerMin===0){
        if(onBreak===false){
          sound.play();
          alert('take a break!');
          timerMin=timerOb.break;
          timerSec=':00';
          onBreak = !onBreak;
        }
        else{
          sound.play();
          alert('back to work!')
          timerMin = timerOb.work;
          timerSec=':00';
          onBreak= !onBreak;
        }
      }
      //case if seconds are in zeroes and there are more minutes, set the seconds to 59 and remove a minute
      timerSec=':59';
      timerMin--;
    }
    console.log(timerMin+timerSec);
    $("#timerDisplay")[0].innerHTML=timerMin+timerSec;  
     
  },1000);
});
//reset function
 $('#reset').click(function(){
   clearInterval(int);
   update();
 })
     
    
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console