Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
    //makes sure the page is loaded first
    $(document).ready(function() {
        var timeInSeconds = 120;
        
        var timeCounter = setInterval(function() {
          timeInSeconds--;
          
          // If we hit 0 seconds clear the timer
          if (timeInSeconds <= 0) {
            clearInterval(timeCounter);
          }
          
          // Display the current time
          displayTime();
        }, 1000);
        function displayTime(){
            // Get the minutes and seconds in whole numbers
            var minutes = Math.floor(timeInSeconds / 60);
            var seconds = timeInSeconds % 60;
            
            // Pad with zeros using the Ternary operator
            seconds = (seconds < 10) ? "0" + seconds : seconds;
            minutes = (minutes < 10) ? "0" + minutes : minutes;
            // Display the countdown
            console.log(minutes + ":" + seconds)
        }
    });
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
JosephGarronepro
0viewers