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.

            
              <div class="container">
  <h1 class="text-center">
    Jack's awesome countdown clock.
  </h1>

  <h3 class="text-center">
    I want to countdown <select class="min-select" id="countId">
      <option value="1">
        1
      </option>
      <option value="2">
        2
      </option>
      <option value="3">
        3
      </option>
      <option value="4">
        4
      </option>
      <option value="5">
        5
      </option>
      <option value="6">
        6
      </option>
      <option value="7">
        7
      </option>
      <option value="8">
        8
      </option>
      <option value="9">
        9
      </option>
      <option value="10">
        10
      </option>
      <option value="11">
        11
      </option>
      <option value="12">
        12
      </option>
      <option value="13">
        13
      </option>
      <option value="14">
        14
      </option>
      <option value="15">
        15
      </option>
      <option value="16">
        16
      </option>
      <option value="17">
        17
      </option>
      <option value="18">
        18
      </option>
      <option value="19">
        19
      </option>
      <option value="20">
        20
      </option>
      <option value="21">
        21
      </option>
      <option value="22">
        22
      </option>
      <option value="23">
        23
      </option>
      <option value="24">
        24
      </option>
      <option value="25">
        25
      </option>
      <option value="26">
        26
      </option>
      <option value="27">
        27
      </option>
      <option value="28">
        28
      </option>
      <option value="29">
        29
      </option>
      <option value="30">
        30
      </option>
      <option value="31">
        31
      </option>
      <option value="32">
        32
      </option>
      <option value="33">
        33
      </option>
      <option value="34">
        34
      </option>
      <option value="35">
        35
      </option>
      <option value="36">
        36
      </option>
      <option value="37">
        37
      </option>
      <option value="38">
        38
      </option>
      <option value="39">
        39
      </option>
      <option value="40">
        40
      </option>
      <option value="41">
        41
      </option>
      <option value="42">
        42
      </option>
      <option value="43">
        43
      </option>
      <option value="44">
        44
      </option>
      <option value="45">
        45
      </option>
      <option value="46">
        46
      </option>
      <option value="47">
        47
      </option>
      <option value="48">
        48
      </option>
      <option value="49">
        49
      </option>
      <option value="50">
        50
      </option>
      <option value="51">
        51
      </option>
      <option value="52">
        52
      </option>
      <option value="53">
        53
      </option>
      <option value="54">
        54
      </option>
      <option value="55">
        55
      </option>
      <option value="56">
        56
      </option>
      <option value="57">
        57
      </option>
      <option value="58">
        58
      </option>
      <option value="59">
        59
      </option>
      <option value="60">
        60
      </option>
    </select> minutes
  </h3>

  <!-- show Display -->
  <div class="container clock">
    <div class="row row-centered">
      <div class="col-xs-6 clock-display">
        <h3 id="time_left">
          00:00
        </h3>
      </div>
    </div><!-- end Display -->
  
    <!-- show Buttons -->
    <div class="row row-centered">
      <div class="col-sm-6 buttons">
        <button class="btn btn-start" id="playpause">Start</button>
      </div>

      <div class="col-sm-6 buttons">
        <button class="btn btn-reset" id="reset">Reset</button>
      </div>
    </div><!-- end Buttons -->
  </div>
</div><!-- end Container -->
            
          
!
            
              body {
  font-family: 'Roboto Slab',serif;
  font-weight: 700;
  background-color: #CBE9F2;
}

.clock {
  background-color: #F0F8FF;
  border: 4px solid #EFEFEF;
  border-radius: 5px;
  -webkit-box-shadow: 0 7px 4px #777;
          box-shadow: 0 7px 4px #777;
  margin-top: 100px;
  padding-bottom: 25px;
  padding-top: 15px;
  width: 50%;
}

.row-centered {
  text-align: center;
}

.clock-display {
  background: rgba(0,0,0,0.06);
  border-radius: 3px;
  webkit-box-shadow: inset 0 4px rgba(0,0,0,0.2);
         box-shadow: inset 0 4px rgba(0,0,0,0.2);
  display: inline-block;
  float: none;
  margin-top: 20px;
  width: 80%;
}

.buttons {
  margin-top: 20px;
}

.btn-start,.btn-reset {
  background: #C4E3F9;
  -webkit-box-shadow: 0 2px 0 0 #269BD0;
             box-shadow: 0 2px 0 0 #99F;
  font-weight: 700;
  height: 35px;
  padding: 4px 20px 0;
  width: 70%;
}

.btn-start:hover,.btn-reset:hover {
  background-color: #8AC7F4;
}

.btn-start:active,.btn-reset:active {
  -webkit-box-shadow: 0 2px 0 0 #B0CCE0;
          box-shadow: 0 2px 0 0 #B0CCE0;
}

.btn-start:before,.btn-reset:before {
  background: #B0CCE0;
  border-right: solid 1px #B0CCE0;
  -webkit-box-shadow: 0 5px 0 0 #B0CCE0;
          box-shadow: 0 5px 0 0 #B0CCE0;
}

.btn-start:active:before,.btn-reset:active:before {
  -webkit-box-shadow: 0 5px 0 0 #B0CCE0,6px 4px 2px rgba(0,0,0,0.3);
          box-shadow: 0 5px 0 0 #B0CCE0,6px 4px 2px rgba(0,0,0,0.3);
}
            
          
!
            
              /*
 * Welcome to my awesome countdown clock!
 */
var counterSelect = document.getElementById('countId'),
        playpause = document.getElementById('playpause'),
            reset = document.getElementById('reset');

/*
 * Provide conditions for initial state.
 */
var counterValue = counterSelect.value * 60,
         playing = false;
renderTime(counterValue);

/*
 * Render a timestamp on the page.
 */
function renderTime(seconds) {
  document.getElementById('time_left').innerHTML = secondsToTime(seconds);
}

/*
 * Output a human readable timestamp given an inital value.
 */
function secondsToTime(seconds) {
    var hours = Math.floor(seconds / 3600);
    seconds -= hours * 3600;
    var minutes = Math.floor(seconds / 60);
    seconds -= minutes * 60;
    if (hours < 1) {
      return leadingZero(minutes) + ':' + leadingZero(seconds);
    } else {
      return hours + ':' + leadingZero(minutes) + ':' + leadingZero(seconds);
    }
}

/*
 * Determine where to place the zeros in a time stamp.
 */
function leadingZero(Time) {
    return (Time < 10) ? "0" + Time : + Time;
}

/*
 * Count down to zero given an initial value.
 */
function countDownFrom(seconds) {
    var audio = new Audio('https://bit.ly/2hQOjct');
    if (playing) {
      if (seconds > 0) {
        setTimeout(function() {
          counterValue = countDownFrom(seconds = seconds - 1)
          renderTime(seconds);
        }, 1000);
      } else {
        audio.play();
        playing = false;
        seconds = 0;
      }
    }
    return seconds;
  }

/* 
 * Handle play/pause click events.
 * Begin or pause the countdown.
 */
playpause.onclick = function() {
  if (!playing) {
    playing = true;
    countDownFrom(counterValue);
    playpause.innerHTML = "Pause";
  } else {
    playpause.innerHTML = "Play";
    playing = false;
  }
};

/*
 * Reset the countdown to the value on the select field.
 * Also pauses the countdown.
 */
reset.onclick = function() {
    playing = false;
    renderTime(selectedCounterValue())
    counterValue = selectedCounterValue();
    playpause.innerHTML = "Start";
  }

/*
 * React to change events on the select field.
 * i.e. change the time rendered and reset the counterValue.
 */
counterSelect.onchange = function(e) {
  renderTime(counterValue = selectedCounterValue());
};

/*
 * Retrieve the current value of the select field.
 */
function selectedCounterValue() {
    return counterSelect.value * 60;
}
            
          
!
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