Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queues - Cara Comfort - Digital clock #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@
</body>
</html>

<script src="index.js"></script>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous">
</script>
<script src="index.js" type="text/javascript"></script>
38 changes: 37 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -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)

});