From 8a35f184b25f060f24aa89d0bfc5427d126ca8f9 Mon Sep 17 00:00:00 2001 From: Cara Comfort Date: Sun, 21 May 2017 21:46:08 -0700 Subject: [PATCH] Made digital clock --- index.html | 7 ++++++- index.js | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 191d3cc..d59f1de 100644 --- a/index.html +++ b/index.html @@ -11,4 +11,9 @@ - + + diff --git a/index.js b/index.js index 877a3aa..2eb45fb 100644 --- a/index.js +++ b/index.js @@ -1 +1,37 @@ -// Your code here + + +$(document).ready(function() { + + // so something show up on the page right away + // var date = new Date(); + // $('#clock').html(date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds()); + + var getTime = function(date) { + var date = new Date(); + var seconds = date.getSeconds(); + var minutes = date.getMinutes(); + var hours = date.getHours(); + + // Change to meridian time + var meridian = 'AM'; + if ( hours >= 12 ) { + hours = hours - 12; + meridian = 'PM'; + } + + var time = addZero(hours) + ':' + addZero(minutes) + ':' + addZero(seconds); + time += ' ' + meridian; + + $('#clock').html(time); + }; + + var addZero = function(time) { + return ( time < 10 ) ? "0" + time : time; + }; + + + + + setInterval(getTime, 1000) + +});