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. 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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 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.

HTML

              
                <div id="timer-container">
  <h2>The time is:</h2>
  <div id="hours" class="timer">000000</div>
  <div class="timer colon"></div>
  <div id="minutes" class="timer">000000</div>
  <div class="timer colon"></div>
  <div id="seconds" class="timer">000000</div>
</div>
              
            
!

CSS

              
                #timer-container {
  border: 1px solid black;
  width: 350px;
  margin: 0 auto;
  padding: 100px;
  text-align: center;
}
  #timer-container .timer {
    display: inline-block;
    font-size: 30px;
    height: 35px;
  }
  #timer-container .colon:after {
    content: ":";
  }  
              
            
!

JS

              
                var hours   = $('#hours');
var minutes = $('#minutes');
var seconds = $('#seconds');
var hoursArray   = [ 0, 0, 0, 0, 0, 0 ];
var minutesArray = [ 0, 0, 0, 0, 0, 0 ];
var secondsArray = [ 0, 0, 0, 0, 0, 0 ];
var binaryMaxTime = 111011;
var binaryMaxHours = 10111;

$(document).ready(function() {
  var timerIsGoing = true;
  
  // establish the current time
  establishTime();
  
  // run the clock
  var myTimer = setInterval(function() {
    incrementTime(secondsArray);
    
    // check if the clock has reached 59 seconds
    if(parseInt(seconds.text()) >= binaryMaxTime) {
      incrementTime(minutesArray);
      
      // check if the clock has reached 59 minutes
      if(parseInt(minutes.text()) >= binaryMaxTime) {
        incrementTime(hoursArray);
        
        // check if the clock has reached 23 hours
        if(parseInt(hours.text()) >= binaryMaxHours)
          clearTime(hoursArray, hours);
        else {
          setTime(hoursArray, hours);
        }
        
        // reset minutes
        clearTime(minutesArray, minutes);
      }
      else {
        // set the seconds
        setTime(minutesArray, minutes);
        //minutes.text('');
        //$.each(minutesArray, function(index, obj){ minutes.prepend(obj); });
      }
      // reset seconds
      clearTime(secondsArray, seconds);
    }
    else {    
      // set the seconds
      setTime(secondsArray, seconds);
      //seconds.text('');
      //$.each(secondsArray, function(index, obj){ seconds.prepend(obj); });
    }
  }, 1000 );
});


// increments the passed array, seconds, minutes, or hours, by 1
function incrementTime(timeArray) {
  timeArray[0] += 1;
  
  for(var i = 0; i < timeArray.length; i++) {
      if(timeArray[i] > 1) {
        timeArray[i] = 0;
        timeArray[i+1]++;
      }
    }// end for-loop
}// end incrementTime(timeArray)


// sets the time (seconds, minutes, or hours)
function setTime(timeArray, whichTime) {
  whichTime.text('');
  $.each(timeArray, function(index, obj){ whichTime.prepend(obj); });
}// end setTime(timeArray, whichTime)


// clears out the passed array, seconds, minutes, or hours, resetting to 0000000
function clearTime(timeArray, whichTime) {
  // clear the array
  for(var i = 0; i < timeArray.length; i++)
        timeArray[i] = 0;
  
  // rewrite time to 0000000
  setTime(timeArray, whichTime);
}// end clearTime(timeArray)


// establish the current time
function establishTime() {
  var date = new Date();
  var hours = date.getHours();
  var minutes = date.getMinutes();
  var seconds = date.getSeconds();
  
  // convert the time to binary
  convertToBinary(hours, minutes, seconds);
}// end establishTime()


// convert time to binary
function convertToBinary(h, m, s) {
  var allTimesArray = [ h, m, s ];
  var temp = [ hoursArray, minutesArray, secondsArray ];
  
  for(var i = 0; i < allTimesArray.length; i++) {
    allTimesArray[i] = allTimesArray[i].toString(2);
    allTimesArray[i] = "000000".substr(allTimesArray[i].length) + allTimesArray[i];
    
    for(var j = 0; j < temp[i].length; j++) {
      temp[i][j] = allTimesArray[i].charAt(j);
    }// end for-loop
    console.log(temp[i]);
  }// end for-loop
  
  // set each time
  setTime(hoursArray.reverse(), hours);
  setTime(minutesArray.reverse(), minutes);
  setTime(secondsArray.reverse(), seconds);
}// end convertToBinary(hours, minutes, seconds)
              
            
!
999px

Console