From 38ed7c5e8fd892b2b164428349a29d8224c37ac5 Mon Sep 17 00:00:00 2001 From: Allison Northrop Date: Fri, 19 May 2017 15:17:11 -0700 Subject: [PATCH 1/5] got the clock showing up --- index.html | 6 +++++- index.js | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 191d3cc..5a2eb07 100644 --- a/index.html +++ b/index.html @@ -7,8 +7,12 @@ -
+
+
+ diff --git a/index.js b/index.js index 877a3aa..2ad5a4e 100644 --- a/index.js +++ b/index.js @@ -1 +1,28 @@ // Your code here +$(document).ready(function() { + var date = $('

' + new Date() + '

'); + // var currentHours = date.getHours(); + // var currentMinutes = date.getMinutes(); + // var currentSeconds = date.getSeconds(); + // var num = 9; + // // console.log(date, currentHours, currentMinutes, currentSeconds); + // + // $('.clock').append(date); + // $('h1').append(num); + $('#clock').append(date); + + for (var i = 0; i < 5; i++) { + // Will execute 5 times + var listItem = $('
  • ' + i + '
  • '); + $('.dynamic-list').append(listItem); +} + + +}); + + + + + // var listItem = $('
  • ' + i + '
  • '); + +// new Date(year, month[, date[, hours[, minutes[, seconds[, milliseconds]]]]]); From 7f37f07deeb2d5f61abb6da72dab937b011204d0 Mon Sep 17 00:00:00 2001 From: Allison Northrop Date: Sun, 21 May 2017 17:33:50 -0700 Subject: [PATCH 2/5] got time function working --- index.html | 2 +- index.js | 26 ++++++++++---------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/index.html b/index.html index 5a2eb07..5ff7195 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,6 @@ -
    @@ -15,4 +14,5 @@ + diff --git a/index.js b/index.js index 2ad5a4e..ae33935 100644 --- a/index.js +++ b/index.js @@ -1,21 +1,15 @@ // Your code here $(document).ready(function() { - var date = $('

    ' + new Date() + '

    '); - // var currentHours = date.getHours(); - // var currentMinutes = date.getMinutes(); - // var currentSeconds = date.getSeconds(); - // var num = 9; - // // console.log(date, currentHours, currentMinutes, currentSeconds); - // - // $('.clock').append(date); - // $('h1').append(num); - $('#clock').append(date); - - for (var i = 0; i < 5; i++) { - // Will execute 5 times - var listItem = $('
  • ' + i + '
  • '); - $('.dynamic-list').append(listItem); -} + + var myVar = setInterval(function(){ time() }, 1000); + + function time() { + var currentDate = new Date(); + var localTime = currentDate.toLocaleTimeString(); + document.getElementById("clock").innerHTML = localTime; + $('#clock').html(localTime); + } + }); From 4cc022ecfb98ee631c6f2aba2bf774d593c02cc5 Mon Sep 17 00:00:00 2001 From: Allison Northrop Date: Sun, 21 May 2017 17:35:41 -0700 Subject: [PATCH 3/5] cleaned up code and used jquery to call html --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index ae33935..eb9bfc3 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,6 @@ $(document).ready(function() { function time() { var currentDate = new Date(); var localTime = currentDate.toLocaleTimeString(); - document.getElementById("clock").innerHTML = localTime; $('#clock').html(localTime); } From a4aa98dc7829ebf981058088f556cbd34e541c03 Mon Sep 17 00:00:00 2001 From: Allison Northrop Date: Sun, 21 May 2017 17:37:11 -0700 Subject: [PATCH 4/5] changed a variable name --- index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/index.js b/index.js index eb9bfc3..c31edd3 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ // Your code here $(document).ready(function() { - var myVar = setInterval(function(){ time() }, 1000); + var secondsInterval = setInterval(function(){ time() }, 1000); function time() { var currentDate = new Date(); @@ -9,8 +9,6 @@ $(document).ready(function() { $('#clock').html(localTime); } - - }); From e2cf41efb05ee590e70ccf71d2a0563447da14f0 Mon Sep 17 00:00:00 2001 From: Allison Northrop Date: Sun, 21 May 2017 17:41:19 -0700 Subject: [PATCH 5/5] added comments to explain process --- index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.js b/index.js index c31edd3..ac168cb 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,17 @@ // Your code here $(document).ready(function() { + //sets the inteval to 1000 milliseconds (1 second). + //this allows the time fucntion to be called every second. var secondsInterval = setInterval(function(){ time() }, 1000); + function time() { + //date class gets current date var currentDate = new Date(); + //toLocaleTimeString takes the current date and converts it var localTime = currentDate.toLocaleTimeString(); + //jquery calls the div where the id is 'clock' and inputs the localTime. The tim fucntion is being called every second and flashes on screen. $('#clock').html(localTime); }