Skip to content

Commit

Permalink
Simple clock in Javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
ArielT committed Feb 6, 2024
1 parent 4339e21 commit 5cc3e74
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@

## Background Color Generator
- simple background gradient generator

## Simple Clock
- simple javascript clock
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ <h1>PREVIEW</h1>
<h2>JS</h2>
<ul>
<li><a href="bg-color-generator\index.html" target="_blank">Background Color Generator</a></li>
<li><a href="simple-clock\index.html" target="_blank">Simple Clock</a></li>
</ul>
</body>
</html>
Binary file added simple-clock/georgiyev-unsplash.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions simple-clock/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<title>Digital Clock</title>
</head>
<body>
<div class="container">
<div class="clock" id="clock">12:00:00</div>
</div>
<script src="script.js"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions simple-clock/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function updateClock() {
const now = new Date();
const hours = now.getHours().toString().padStart(2, '0');
const minutes = now.getMinutes().toString().padStart(2, '0');
const seconds = now.getSeconds().toString().padStart(2, '0');
const timeString = `${hours}:${minutes}:${seconds}`;

document.getElementById('clock').innerText = timeString;
}

setInterval(updateClock, 1000); // Update the clock every second
26 changes: 26 additions & 0 deletions simple-clock/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@import url('https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap');
body {
margin: 0;
padding: 0;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background-image: url('georgiyev-unsplash.jpg');
background-size: cover;
background-position: center;
}

.container {
text-align: center;
}

.clock {
font-family: 'Source Code Pro', monospace;
font-size: 2em;
color: #fff;
background: rgba(8, 8, 8, 0.5);
padding: 10px;
border-radius: 10px;
display: inline-block;
}

0 comments on commit 5cc3e74

Please sign in to comment.