Skip to content

Queues - Tamiko Terada - js-digital-clock #46

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

Open
wants to merge 3 commits 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
8 changes: 6 additions & 2 deletions index.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
body {
background-color: #80d4ea;
background-color: lightpink;
/* old color 80d4ea */
}

#clock {
Expand All @@ -8,9 +9,12 @@ body {
margin: auto;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
padding-top: 70px;
font-family: courier, monospace;
text-align: center;
color: white;
font-size: 100px;
}

#clock p {
font-size: 50px;
}
9 changes: 6 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
</head>

<body>
<div id='clock'></div>
<div id='clock'>
</div>

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="index.js"></script>

</body>
</html>

<script src="index.js"></script>
28 changes: 27 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
// Your code here

//as soon as document is loaded

var toClockString = function(number) {
var str_time = number.toString();
if (str_time.length === 1) {
return "0" + str_time;
} else {
return str_time;
}
};

var showTime = function(now) {
var hours = toClockString(now.getHours()),
minutes = toClockString(now.getMinutes()),
seconds = toClockString(now.getSeconds());

var date = now.toDateString();
$("#clock").html('<div>' + hours + ":" + minutes + ":" + seconds + '</div>' + '<p>' + date + '</p>');
};

$(document).ready(function(){
setInterval(function(){
var now = new Date();
showTime(now);
}, 1000);
});