HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<!-- #CodePenChallenge: Timekeeping -->
<div class="background">
<div class="watch-container">
<div class="top-band"></div>
<div class="watch-case">
<div class="watch-face">
<!-- START OF TOP SECTION -->
<div class="top">
<div class="internet-button-container">
<button type="button" class="internet-button" onclick="launchInternet()"><img src="https://adevelopersprofile.com/CodePen/Challenges/Watch/internet.png" alt="Internet Icon"></button>
</div>
<div class="clear-button-container hide">
<button type="button" class="btn-small" id="clear-alarm-event-button" onclick="clearAlarmEvent()">CLEAR</button>
</div>
<div class="sideBarNavMenu">
<span id="sideNavIcon" onclick="openSideNav()">☰</span>
</div>
<div class="sideNavBar" id="sideNav">
<ul class="navListMenu">
<li><a href="javascript:void(0)" class="closeBtn" onclick="closeSideNav()">×</a></li>
<li>
<div class="menuItem">
<img class="icon" src="https://adevelopersprofile.com/CodePen/Challenges/Watch/alarm.png" alt="Set Alarm Icon">
<span onclick="setAlarm()">Alarm</span>
</div>
</li>
<li>
<div class="menuItem">
<img class="icon" src="https://adevelopersprofile.com/CodePen/Challenges/Watch/future.png" alt="Set Event Icon">
<span onclick="setEvent()">Set Future Event</span>
</div>
</li>
<li>
<div class="menuItem">
<img class="icon" src="https://adevelopersprofile.com/CodePen/Challenges/Watch/settings.png" alt="Settings Icon">
<span>Settings</span>
</div>
</li>
</ul>
</div>
</div>
<!-- END OF TOP SECTION -->
<!-- START OF CENTER SECTION -->
<div class="center">
<div class="home-screen">
<div class="time-display"></div>
</div>
<div class="timer-screen hide">
<div class="timer-display hide"></div>
</div>
<div class="function-screen hide">
<div class="function-title-container">
<div class="function-title"></div>
<div class="doom-select doom-container hide">
<p class="doom-select hide" id="doom-button-label">DOOMSDAY:</p>
<label class="doom-select doom-toggle hide">
<input type="checkbox" name="doom-checkbox" id="doom-checkbox" class="doom-select" onchange="setDoomsday()">
<span class="doom-select slider round hide"></span>
</label>
</div>
</div>
<div class="date-function" id="date-input">
<div class="date-function date-field hide">
<div class="date-function date-field-display hide">
<p class="date-function" id="month-field"></p>
</div>
<div class="date-function incr-decr-btn-container hide">
<button type="button" class="date-function func-btn hide" id="decr-month" onclick="decreaseMonth()">-</button>
<button type="button" class="date-function func-btn hide" id="incr-month" onclick="increaseMonth()">+</button>
</div>
</div>
<div class="date-function date-field hide">
<div class="date-function date-field-display hide">
<p class="date-function hide" id="day-field"></p>
</div>
<div class="date-function incr-decr-btn-container hide">
<button type="button" class="date-function func-btn hide" id="decr-day" onclick="decreaseDay()">-</button>
<button type="button" class="date-function func-btn hide" id="incr-day" onclick="increaseDay()">+</button>
</div>
</div>
<div class="date-function date-field hide">
<div class="date-function date-field-display hide">
<p class="date-function hide" id="year-field"></p>
</div>
<div class="date-function incr-decr-btn-container hide">
<button type="button" class="date-function func-btn hide" id="decr-year" onclick="decreaseYear()">-</button>
<button type="button" class="date-function func-btn hide" id="incr-year" onclick="increaseYear()">+</button>
</div>
</div>
</div>
<div class="time-function hide" id="time-input">
<div class="time-function time-field hide">
<div class="time-function time-field-display hide">
<p class="time-function hide" id="hour-field"></p>
</div>
<div class="time-function incr-decr-btn-container hide">
<button type="button" class="time-function func-btn hide" id="decr-hour" onclick="decreaseHour()">-</button>
<button type="button" class="time-function func-btn hide" id="incr-hour" onclick="increaseHour()">+</button>
</div>
</div>
<div class="time-function time-field hide">
<div class="time-function time-field-display hide">
<p class="time-function hide" id="minute-field"></p>
</div>
<div class="time-function incr-decr-btn-container hide">
<button type="button" class="time-function func-btn hide" id="decr-minute" onclick="decreaseMinute()">-</button>
<button type="button" class="time-function func-btn hide" id="incr-minute" onclick="increaseMinute()">+</button>
</div>
</div>
</div>
<div class="internet-screen hide" id="internet-display">
<iframe src="https://css-tricks.com/" title="Internet" id="internet-iframe" class="internet-screen hide"></iframe>
</div>
</div>
</div>
<!-- END OF CENTER SECTION -->
<!-- START OF BOTTOM SECTION -->
<div class="bottom">
<button type="button" class="btn left" id="left-button" onclick="getWeather()"></button>
<button type="button" class="btn middle" id="middle-button" onclick="getEmail()"></button>
<button type="button" class="btn right" id="right-button" onclick="loadTimer()"></button>
<button type="button" class="btn hide" id="function1" onclick="function1Click()"></button>
<button type="button" class="btn hide" id="function2" onclick="function2Click()"></button>
<button type="button" class="btn hide" id="function3" onclick="function3Click()"></button>
</div>
<!-- END OF BOTTOM SECTION -->
</div>
</div>
<div class="bottom-band"></div>
</div>
</div>
* {
box-sizing: border-box;
}
.background,
.watch-case,
.watch-face,
.function-title-container{
display: flex;
flex-direction: column;
}
.background,
.watch-case {
justify-content: center;
align-items: center;
}
.background {
width: 100vw;
height: 100vh;
background-color: #000000;
}
.watch-container {
background-color: #ffffff;
}
.top-band,
.bottom-band {
background-repeat: no-repeat;
background-size: cover;
}
.top-band {
background-image: url("https://adevelopersprofile.com/CodePen/Challenges/Watch/top_band.png");
}
.bottom-band {
background-image: url("https://adevelopersprofile.com/CodePen/Challenges/Watch/bottom_band.png");
margin-left: 0.5%;
}
.watch-case {
background-color: #000000;
border-radius: 15px;
}
.watch-face {
background-image: url("https://adevelopersprofile.com/CodePen/Challenges/Watch/watch_face.jpg");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
border-radius: 15px;
}
.top,
.bottom {
width: 100%;
height: 20%;
}
.top,
.bottom,
.clear-button-container {
display: flex;
flex-direction: row;
}
.top {
position: relative;
}
.center {
width: 100%;
height: 60%;
}
.internet-button {
background: transparent;
border: none;
cursor: pointer;
}
.home-screen,
.timer-screen,
.function-screen {
width: 100%;
height: 100%;
text-align: center;
}
.time-display,
.timer-display,
.function-title{
font-family: "Helvetica Neue", Helvetica, Arial;
color: #ffffff;
}
.internetScreen {
width: 95%;
height: 95%;
}
#clear-alarm-event-button:hover {
cursor: pointer;
}
.btn {
width: 25%;
height: 80%;
border-radius: 10px;
border: 2px solid #696969;
background-color: black;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
margin: 0.5% 0 0 5.5%;
}
.btn:hover {
cursor: pointer;
}
.left:hover {
background-image: url("https://adevelopersprofile.com/CodePen/Challenges/Watch/weather_icon.png");
}
.middle:hover {
background-image: url("https://adevelopersprofile.com/CodePen/Challenges/Watch/email_icon.png");
background-position: center;
}
.right:hover {
background-image: url("https://adevelopersprofile.com/CodePen/Challenges/Watch/timer_icon.png");
background-position: center;
}
.btn-small {
width: 50%;
height: 50%;
}
.hide {
display: none;
}
.show {
display: block;
}
.startTimer,
.stopTimer,
.resetTimer,
.back,
.home {
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.startTimer {
background-image: url("https://adevelopersprofile.com/CodePen/Challenges/Watch/play_icon.png");
}
.stopTimer {
background-image: url("https://adevelopersprofile.com/CodePen/Challenges/Watch/stop_icon.png");
}
.resetTimer {
background-image: url("https://adevelopersprofile.com/CodePen/Challenges/Watch/reset_icon.jpg");
}
.back {
background-image: url("https://adevelopersprofile.com/CodePen/Challenges/Watch/back_icon.png");
}
.home {
background-image: url("https://adevelopersprofile.com/CodePen/Challenges/Watch/home_icon.png");
}
.set,
.cancel {
text-align: center
}
.set {
background-color: lime;
color: black;
}
.cancel {
background-color: red;
color: white;
}
#date-input,
#time-input,
.date-field,
.time-field {
display: flex;
flex-direction: row;
-webkit-user-select: none; /* Safari */
-ms-user-select: none; /* IE 10 and IE 11 */
user-select: none; /* Standard syntax */
}
.incr-decr-btn-container {
display: flex;
flex-direction: column;
}
.date-field-display,
.time-field-display {
background-color: white;
color: black;
}
/* INTERNET */
#internet-display {
width: 100%;
height: 100%;
}
#internet-iframe {
width: 100%;
height: 100%;
border: none;
}
.center-display{
margin-top: 20%;
}
/*** MENU ***/
.sideBarNavMenu {
position: absolute;
right: 5%;
}
.sideNavBar {
position: absolute;
top: 0;
right: 0;
z-index: 11;
transition: 0.5s;
overflow-x: hidden;
overflow-y: hidden;
background-color: #000000;
font-family: "Helvetica Neue", Helvetica, sans-serif;
margin-top: -1%;
}
#sideNavIcon {
margin: 2% 0 0 3%;
text-decoration: none;
}
.closeBtn {
position: absolute;
top: 0;
right: 3%;
color: #ffffff;
text-decoration: none;
margin: 2% 2% 0 0;
}
#sideNavIcon {
color: #696969;
font-size: 35px;
cursor: pointer;
}
.sideNavBar {
position: absolute;
top: 10%;
}
.sideNavBar {
top: 2%;
right: 0;
color: #ffffff;
}
.sideNavBar li {
color: #ffffff;
transition: 0.3s;
}
.sideNavBar {
justify-content: center;
}
.navBarList {
text-align: left;
}
.navListMenu li:nth-child(1) {
margin-top: 20%;
}
.menuItem {
display: flex;
flex-direction: row;
align-items: center;
}
span:hover {
cursor: pointer;
text-decoration: underline;
}
/* ACTIVE CLASS */
.active {
background-color: rgb(121, 121, 121);
text-shadow: 1px 1px #dadada;
}
.activeDropDown {
background-color: #000000;
text-shadow: 1px 1px #cecece;
}
#sideNav {
display: none;
}
/* ONCLICK CLASSES */
.sideNavBarDisplay {
overflow: hidden;
}
.sideNavBarHide {
width: 0;
height: 0;
}
.navListMenu {
list-style-type: none;
}
/*** END OF MENU ***/
/*** DOOMSDAY TOGGLE BUTTON ***/
.doom-container {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
#doom-button-label {
margin-right: 5%;
}
/* The switch - the box around the slider */
.doom-toggle {
position: relative;
/*display: inline-block; */
}
/* Hide default HTML checkbox */
.doom-toggle input {
opacity: 0;
width: 0;
height: 0;
}
/* The slider */
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: 0.4s;
transition: 0.4s;
}
.slider:before {
position: absolute;
content: "";
background-color: white;
-webkit-transition: 0.4s;
transition: 0.4s;
}
input:checked + .slider {
background-color: lime;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196f3;
}
/* Rounded sliders */
.slider.round:before {
border-radius: 50%;
}
/* GIF CLASSES */
.alarm,
.celebration,
.doomsDay {
background-repeat: no-repeat;
background-position: center;
}
.alarm {
background-image: url("https://i.pinimg.com/originals/09/aa/0f/09aa0f6d2d73d1c0d8ac950b5a43456e.gif");
background-size: contain;
}
.celebration {
background-image: url("https://adevelopersprofile.com/CodePen/Challenges/Watch/fireworks.gif");
background-size: cover;
}
.doomsDay {
background-image: url("https://adevelopersprofile.com/CodePen/Challenges/Watch/nuclear.gif");
background-size: cover;
}
/*** START OF MEDIA QUERIES ***/
/* 280+ */
@media screen and (min-width: 20em) {
.watch-container {
width: 270px;
height: 400px;
}
.top-band,
.bottom-band {
width: 70%;
height: 8.5%;
margin: 0 auto;
}
.top-band {
margin-bottom: -2%;
}
.bottom-band {
margin-top: -2%;
}
.watch-case {
width: 85%;
height: 82%;
margin: 2% auto;
}
.watch-face {
width: 90%;
height: 92%;
}
/* TOP SECTION */
.internet-button-container {
width: 50%;
margin: 5% 0 0 0;
}
.internet-button{
width: 100%;
}
.internet-button img{
width: 30%;
margin: -6% 0 0 -60%;
}
.clear-button-container {
width: 45%;
height: 70%;
margin: 0 -20%;
}
#clear-alarm-event-button {
width: 100%;
height: 100%;
background-color: red;
color: white;
border-radius: 10px;
margin: 0 auto 0 -3%;
}
#sideNavIcon {
font-size: 25px;
}
.sideNavBarDisplay {
width: 90%;
height: 400%;
}
.sideBarNav li{
margin: 5% 0 5% 0;
}
.icon {
width: 25px;
height: 25px;
margin: 7% 10% 10% -10%;
}
.menuItem span{
margin-top: -2%;
}
/* CENTER SECTION */
.home-screen, .timer-screen {
margin: 25% auto;
}
.function-screen {
margin: 0 0 0 0;
}
.function-title-container{
margin-top: -5%;
}
.doom-container{
margin: -2% 0 1% 0;
padding: 0 0 0 0;
}
.doom-toggle{
width: 30px;
height: 15px;
}
.slider:before {
height: 14px;
width: 15px;
left: 1px;
bottom: 1px;
}
input:checked + .slider:before {
-webkit-transform: translateX(15px);
-ms-transform: translateX(15px);
transform: translateX(15px);
}
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
#date-input, #time-input {
width: 95%;
margin-left: 3%;
}
#time-input{
margin: 8% 0 0 10%;
}
.time-field, .date-field, .date-field-display{
width: 100%;
}
.date-field-display, .time-field-display{
height: 45px;
}
.date-field:nth-child(2) {
margin: 0 2% 0 2%;
}
.time-field:nth-child(2) {
margin-left: 4%;
}
.time-field-display{
width: 50%;
margin-right: 2%;
}
.incr-decr-btn-container{
margin-top -0.5%;
}
.func-btn{
height: 23px;
text-align: center;
}
#internet-display {
width: 98%;
margin: -10% 0 0 0.5%;
}
/*** FONTS ***/
.sideNavBar {
font-size: 1em;
}
.sideNavBar li {
font-size: 0.95em;
}
.closeBtn {
font-size: 3em;
}
.time-display,
.timer-display {
font-size: 1.75em;
}
#clear-alarm-event-button {
font-size: 0.75em;
}
#doom-button-label {
font-size: 0.75em;
color: #ffffff;
}
.set {
font-size: 0.85em;
font-weight: bold;
}
.cancel {
font-size: 1em;
font-weight: bold;
}
.function-title {
font-size: 1.3em;
}
#month-field,
#day-field,
#year-field {
font-size: 1em;
}
#hour-field,
#minute-field {
font-size: 1em;
}
}
/*
@media screen and (min-width: 30em) {
}
@media screen and (min-width: 40em) {
}
/* LARGE FORMAT
@media screen and (min-width: 50em) {
}
@media screen and (min-width: 80em) {
}
@media screen and (min-width: 150em) {
}
*/
/*** BOOL ***/
let boolDisplayTime = true;
let startStopTimer = false;
let alarmONOFF = false;
let eventONOFF = false;
let boolClearAlarm = false;
let boolClearEvent = false;
let boolDoomsDay = false;
/*** NUMERIC ***/
let counter = 0;
let function1ClickCount = 0;
let totalSeconds = 0;
let alarmHour = 0;
let alarmMinute = 0;
let eventHour = 0;
let eventMinute = 0;
let eventMonth = 0;
let eventDay = 0;
let minHour = 0;
let minMinute = 0;
let minMonth = 1; // 0 = January
let minDay = 1; //
let minYear = 1970;
let maxHour = 23;
let maxMinute = 59;
let maxMonth = 12; // 11 = Deceneber
let numDays = 0; // Max Day
let maxYear = 2072;
let tempHour = 0;
let tempMinute = 0;
let tempMonth = 0;
let tempDay = 0;
let tempDate = new Date();
let tempYear = parseInt(tempDate.getFullYear());
let eventYear = tempYear;
/*** DATE ***/
let eventDate = new Date();
/*** STRING ***/
let currentFunction = "none";
let displayHours = "00";
let displayMinutes = "00";
let displaySeconds = "00";
/*** DOCUMENT ELEMENTS ***/
let alarmEventScreen = document.querySelector(".center");
let displayTimeScreen = document.querySelector(".home-screen");
let displayTimerScreen = document.querySelector(".timer-screen");
let displayTime = document.querySelector(".time-display");
let displayTimer = document.querySelector(".timer-display");
let functionScreen = document.querySelector(".function-screen");
let functionTitleContainer = document.querySelector(
".function-title-container"
);
let functionTitle = document.querySelector(".function-title");
let dateInputScreen = document.querySelectorAll(".date-function");
let timeInputScreen = document.querySelectorAll(".time-function");
let internetScreen = document.querySelectorAll(".internet-screen");
let clearButton = document.querySelector(".clear-button-container");
let doomLabel = document.querySelector("#doom-label");
let leftButton = document.querySelector("#left-button");
let middleButton = document.querySelector("#middle-button");
let rightButton = document.querySelector("#right-button");
let functionButton1 = document.querySelector("#function1");
let functionButton2 = document.querySelector("#function2");
let functionButton3 = document.querySelector("#function3");
let submitClearButtons = document.querySelector(".btn-small");
/*** END OF DOCUMENT ELEMENTS ***/
/*** START OF FUNCTION BUTTONS ***/
function function1Click() {
// SET BUTTON
switch (currentFunction) {
case "alarm":
alarmONOFF = true;
alarmHour = tempHour;
alarmMinute = tempMinute;
functionTitle.innerHTML = "ALARM SET";
break;
case "event":
eventONOFF = true;
eventHour = parseInt(tempHour);
eventMinute = parseInt(tempMinute);
eventMonth = parseInt(tempMonth - 1);
eventDay = parseInt(tempDay);
eventYear = parseInt(tempYear);
functionTitle.innerHTML = "EVENT SET";
break;
case "timer":
if (function1ClickCount === 0) {
functionButton1.classList.remove("startTimer");
functionButton1.classList.add("stopTimer");
startStopTimer = true;
function1ClickCount++;
} else {
functionButton1.classList.remove("stopTimer");
functionButton1.classList.add("startTimer");
startStopTimer = false;
function1ClickCount = 0;
}
break;
}
}
function function2Click() {
// RESET/CLEAR BUTTON
switch (currentFunction) {
case "alarm":
alarmONOFF = false;
alarmHour = 0;
alarmMinute = 0;
tempHour = 0;
tempMinute = 0;
updateHour();
updateMinute();
functionTitle.innerHTML = "ALARM CLEARED";
break;
case "event":
eventONOFF = false;
eventHour = 0;
eventMinute = 0;
tempHour = 0;
tempMinute = 0;
updateHour();
updateMinute();
eventMonth = 0;
eventDay = 0;
eventYear = parseInt(tempDate.getFullYear());
tempMonth = 0;
tempDay = 0;
tempYear = eventYear;
updateMonth();
updateDay();
updateYear();
functionTitle.innerHTML = "EVENT CLEARED";
break;
case "timer":
resetTimer();
displayTimer.innerHTML = "00:00:00";
break;
}
}
function function3Click() {
// BACK BUTTON
switch (currentFunction) {
case "alarm":
removeAlarmIcons();
hideAlarmDisplay();
hideFunctionScreen();
tempHour = 0;
tempMinute = 0;
functionTitle.innerHTML = "";
boolDisplayTime = true;
break;
case "event":
removeAlarmIcons();
hideEventDisplay();
hideFunctionScreen();
tempHour = 0;
tempMinute = 0;
tempMonth = 0;
tempDay = 0;
tempYear = parseInt(tempDate.getFullYear());
functionTitle.innerHTML = "";
hideDoomsDay();
boolDisplayTime = true;
break;
case "timer":
removeTimerIcons();
hideFunctionScreen();
hideTimerDisplay();
boolDisplayTime = true;
break;
case "internet":
hideInternetScreen();
hideFunctionScreen();
boolDisplayTime = true;
break;
}
currentFunction = "none";
}
/*** END OF FUNCTION BUTTONS ***/
/*** START OF TIME AND TIMER FUNCTIONS ***/
setInterval(getCurrentTime, 1000);
function getCurrentTime() {
let date = new Date();
let currentTime = date.toLocaleTimeString();
// Delay for alarm and event reset
if (!boolClearAlarm) {
checkAlarm(date);
}
if (!boolClearEvent) {
checkEvent(date);
}
displayTimeOrFunction(currentTime);
}
function displayTimeOrFunction(currentTime) {
displayTime.innerHTML = currentTime;
boolDisplayTime ? showTimeDisplay() : hideTimeDisplay();
}
let setTimer = setInterval(timer, 1000);
function timer() {
if (startStopTimer) {
totalSeconds++;
let hours = Math.floor(totalSeconds / 3600);
let minutes = Math.floor((totalSeconds - hours * 3600) / 60);
let seconds = totalSeconds - (hours * 3600 + minutes * 60);
if (hours < 10) {
displayHours = "0" + hours;
} else {
displayHours = hours;
}
if (minutes < 10) {
displayMinutes = "0" + minutes;
} else {
displayMinutes = minutes;
}
if (seconds < 10) {
displaySeconds = "0" + seconds;
} else {
displaySeconds = seconds;
}
displayTimer.innerHTML =
displayHours + ":" + displayMinutes + ":" + displaySeconds;
}
}
function loadTimer() {
// Sets the watch to the timer function
boolDisplayTime = false;
currentFunction = "timer";
showFunctionScreen();
addTimerIcons();
if (totalSeconds < 1) {
displayTimer.innerHTML = "00:00:00";
}
showTimerDisplay();
}
function resetTimer() {
totalSeconds = 0;
}
/*** END OF TIME AND TIMER FUNCTIONS ***/
/*** START OF FUNCTION FEATURES ***/
let hourField = document.querySelector("#hour-field");
let minuteField = document.querySelector("#minute-field");
let monthField = document.querySelector("#month-field");
let dayField = document.querySelector("#day-field");
let yearField = document.querySelector("#year-field");
let doomSelect = document.querySelectorAll(".doom-select");
let doomCheckbox = document.querySelector("#doom-checkbox");
function setDoomsday() {
doomCheckbox.checked ? (boolDoomsDay = true) : (boolDoomsDay = false);
}
function activateAlarm() {
currentFunction = "alarm";
boolDisplayTime = false;
alarmEventScreen.classList.add("alarm");
clearButton.classList.add("show");
}
function activateEvent() {
currentFunction = "event";
boolDisplayTime = false;
boolDoomsDay
? alarmEventScreen.classList.add("doomsDay")
: alarmEventScreen.classList.add("celebration");
clearButton.classList.add("show");
}
function checkAlarm(date) {
if (alarmONOFF) {
let thisHour = date.getHours();
let thisMinute = date.getMinutes();
if (thisHour == alarmHour && thisMinute == alarmMinute) {
activateAlarm();
}
}
}
function checkEvent(date) {
if (eventONOFF) {
let thisMonth = date.getMonth();
let thisDay = date.getDate();
let thisYear = date.getFullYear();
let thisHour = date.getHours();
let thisMinute = date.getMinutes();
if (
thisMonth == eventMonth &&
thisDay == eventDay &&
thisYear == eventYear &&
thisHour == eventHour &&
thisMinute == eventMinute
) {
activateEvent();
}
}
}
function clearAlarmEvent() {
switch (currentFunction) {
case "alarm":
boolClearAlarm = true;
alarmEventScreen.classList.remove("alarm");
// Disable alarm check for 1 minute
setTimeout(function () {
boolClearAlarm = false;
}, 60000);
break;
case "event":
boolClearEvent = true;
if (boolDoomsDay) {
alarmEventScreen.classList.remove("doomsDay");
} else {
alarmEventScreen.classList.remove("celebration");
}
// Disable event check for 1 minute
setTimeout(function () {
boolClearEvent = false;
}, 60000);
break;
}
currentFunction = "none";
boolDisplayTime = true;
clearButton.classList.remove("show");
clearButton.classList.add("hide");
}
function setAlarm() {
currentFunction = "alarm";
boolDisplayTime = false;
functionTitle.innerHTML = "ALARM";
closeSideNav();
addAlarmIcons();
showAlarmDisplay();
tempHour = alarmHour;
tempMinute = alarmMinute;
}
function setEvent() {
currentFunction = "event";
boolDisplayTime = false;
functionTitle.innerHTML = "EVENT";
closeSideNav();
addAlarmIcons();
showEventDisplay();
showDoomsDay();
tempHour = eventHour;
tempMinute = eventMinute;
if (eventMonth > 0 && eventDay > 0) {
tempMonth = eventMonth + 1; // SET MONTH TO 1 - 12 FROM 0 - 11
}
tempDay = eventDay;
tempYear = parseInt(eventYear);
}
function launchInternet() {
currentFunction = "internet";
boolDisplayTime = false;
hideButtons();
addInternetIcons();
showFunctionButtons();
showInternetScreen();
showFunctionScreen();
}
function getNumberOfDays(currentMonth, currentYear) {
/* 0 = Jan, 1 = Feb, 2 = March, 3 = April, 4 = May, 5 = June, 6 = July, 7 = August, 8 = Sep, 9 = Oct,
10 = Nov, 11 = Dec; */
let days = 0;
let month = currentMonth - 1;
switch (month) {
case 0:
case 2:
case 4:
case 6:
case 7:
case 9:
case 11:
days = 31;
break;
case 3:
case 5:
case 8:
case 10:
days = 30;
break;
case 1:
let leap = checkLeapYear(currentYear);
if (leap) {
days = 29;
} else {
days = 28;
}
break;
}
return days;
}
function checkLeapYear(currentYear) {
return true
? (currentYear % 100 === 0 || currentYear % 400 !== 0) && currentYear % 4 == 0
: false;
}
function checkDay() {
if (tempDay > numDays) {
tempDay = numDays;
updateDay();
}
}
/* INCREMENT/DECREMENT BUTTONS */
/* TIME */
function decreaseHour() {
if (tempHour > minHour) {
tempHour--;
} else {
tempHour = maxHour;
}
updateHour();
}
function increaseHour() {
if (tempHour < maxHour) {
tempHour++;
} else {
tempHour = minHour;
}
updateHour();
}
function decreaseMinute() {
if (tempMinute > minMinute) {
tempMinute--;
} else {
tempMinute = maxMinute;
}
updateMinute();
}
function increaseMinute() {
if (tempMinute < maxMinute) {
tempMinute++;
} else {
tempMinute = minMinute;
}
updateMinute();
}
/* DATE */
function decreaseMonth() {
if (tempMonth > minMonth) {
tempMonth--;
} else {
tempMonth = maxMonth;
}
updateMonth();
numDays = getNumberOfDays(tempMonth);
checkDay();
}
function increaseMonth() {
if (tempMonth < maxMonth) {
tempMonth++;
} else {
tempMonth = minMonth;
}
updateMonth();
numDays = getNumberOfDays(tempMonth, tempYear);
checkDay();
}
function decreaseDay() {
if (tempDay > minDay) {
tempDay--;
} else {
tempDay = numDays;
}
updateDay();
}
function increaseDay() {
if (tempDay < numDays) {
tempDay++;
} else {
tempDay = minDay;
}
updateDay();
}
function decreaseYear() {
if (tempYear > minYear) {
tempYear--;
} else {
tempYear = parseInt(maxYear);
}
updateYear();
}
function increaseYear() {
if (tempYear < maxYear) {
tempYear++;
} else {
tempYear = pasreInt(minYear);
}
updateYear();
}
/* END OF INCREMENT/DECREMENT DATA */
/* UPDATE FIELD DATA */
/* TIME */
function updateHour() {
let value = "";
tempHour < 10 ? (value = "0" + tempHour) : (value = tempHour);
hourField.innerHTML = value;
}
function updateMinute() {
let value = "";
tempMinute < 10 ? (value = "0" + tempMinute) : (value = tempMinute);
minuteField.innerHTML = value;
}
/* DATE */
function updateMonth() {
let value = "";
tempMonth < 10 ? (value = "0" + tempMonth) : (value = tempMonth);
monthField.innerHTML = value;
}
function updateDay() {
let value = "";
tempDay < 10 ? (value = "0" + tempDay) : (value = tempDay);
dayField.innerHTML = value;
}
function updateYear() {
yearField.innerHTML = tempYear;
}
/*** END OF FUNCTION FEATURES ***/
/*** NAVIGATION ***/
function openSideNav() {
// Adds the display navigation menu class to sideBarNav
sideNav = document.getElementById("sideNav");
sideNav.style.display = "block";
sideNav.classList.remove("sideNavBarHide");
sideNav.classList.add("sideNavBarDisplay");
}
function closeSideNav() {
// Adds the hide navigation menu class to sideNavBar
sideNav = document.getElementById("sideNav");
sideNav.classList.remove("sideNavBarDisplay");
sideNav.classList.add("sideNavBarHide");
}
/*** DISPLAY ***/
/* TIME */
function hideTimeDisplay() {
displayTimeScreen.classList.remove("show");
displayTimeScreen.classList.add("hide");
}
function showTimeDisplay() {
displayTimeScreen.classList.remove("hide");
displayTimeScreen.classList.add("show");
}
/* TIMER */
function hideTimerDisplay() {
displayTimerScreen.classList.remove("show");
displayTimerScreen.classList.add("hide");
displayTimer.classList.remove("show");
displayTimer.classList.add("hide");
}
function showTimerDisplay() {
displayTimerScreen.classList.remove("hide");
displayTimerScreen.classList.add("show");
displayTimer.classList.remove("hide");
displayTimer.classList.add("show");
}
/* ALARM */
function hideAlarmDisplay() {
hideFunctionScreen();
functionTitle.classList.remove("center-display");
timeInputScreen.forEach(function (inputItem) {
inputItem.classList.remove("show");
inputItem.classList.add("hide");
});
hourField.innerHTML = "";
minuteField.innerHTML = "";
}
function showAlarmDisplay() {
showFunctionScreen();
functionTitle.classList.add("center-display");
timeInputScreen.forEach(function (inputItem) {
inputItem.classList.remove("hide");
inputItem.classList.add("show");
});
if (alarmHour == 0 && alarmMinute == 0) {
hourField.innerHTML = "HH";
minuteField.innerHTML = "MM";
}
}
/* EVENT */
function hideEventDisplay() {
hideFunctionScreen();
hideDoomsDay();
dateInputScreen.forEach(function (inputItem) {
inputItem.classList.remove("show");
inputItem.classList.add("hide");
});
timeInputScreen.forEach(function (inputItem) {
inputItem.classList.remove("show");
inputItem.classList.add("hide");
});
/*hourField.innerHTML = "";
minuteField.innerHTML = "";
monthField.innerHTML = "";
dayField.innerHTML = "";
yearField.innerHTML = "";*/
}
function showEventDisplay() {
showFunctionScreen();
showDoomsDay();
dateInputScreen.forEach(function (inputItem) {
inputItem.classList.remove("hide");
inputItem.classList.add("show");
});
timeInputScreen.forEach(function (inputItem) {
inputItem.classList.remove("hide");
inputItem.classList.add("show");
});
if (eventHour == 0 && eventMinute == 0) {
hourField.innerHTML = "HH";
minuteField.innerHTML = "MM";
}
if (eventMonth == 0 && eventDay == 0) {
monthField.innerHTML = "MM";
dayField.innerHTML = "DD";
}
yearField.innerHTML = tempYear;
}
/* INTERNET */
function hideInternetScreen() {
internetScreen.forEach(function (inputItem) {
inputItem.classList.remove("show");
inputItem.classList.add("hide");
});
}
function showInternetScreen() {
internetScreen.forEach(function (inputItem) {
inputItem.classList.remove("hide");
inputItem.classList.add("show");
});
}
/* FUNCTION SCREEN */
function hideFunctionScreen() {
functionScreen.classList.remove("show");
functionScreen.classList.add("hide");
functionTitle.classList.remove("show");
functionTitle.classList.add("hide");
hideFunctionButtons();
showButtons();
showTimeDisplay();
}
function showFunctionScreen() {
hideTimeDisplay();
functionScreen.classList.remove("hide");
functionScreen.classList.add("show");
functionTitle.classList.remove("hide");
functionTitle.classList.add("show");
hideButtons();
showFunctionButtons();
}
/* BUTTONS */
function hideButtons() {
leftButton.classList.remove("show");
middleButton.classList.remove("show");
rightButton.classList.remove("show");
leftButton.classList.add("hide");
middleButton.classList.add("hide");
rightButton.classList.add("hide");
}
function showButtons() {
leftButton.classList.remove("hide");
middleButton.classList.remove("hide");
rightButton.classList.remove("hide");
leftButton.classList.add("show");
middleButton.classList.add("show");
rightButton.classList.add("show");
}
function hideFunctionButtons() {
functionButton1.classList.remove("show");
functionButton2.classList.remove("show");
functionButton3.classList.remove("show");
functionButton1.classList.add("hide");
functionButton2.classList.add("hide");
functionButton3.classList.add("hide");
}
function showFunctionButtons() {
functionButton1.classList.remove("hide");
functionButton2.classList.remove("hide");
functionButton3.classList.remove("hide");
functionButton1.classList.add("show");
functionButton2.classList.add("show");
functionButton3.classList.add("show");
}
function addTimerIcons() {
functionButton1.classList.add("startTimer");
functionButton2.classList.add("resetTimer");
functionButton3.classList.add("back");
}
function removeTimerIcons() {
functionButton1.classList.remove("startTimer");
functionButton2.classList.remove("resetTimer");
functionButton3.classList.remove("back");
}
function addAlarmIcons() {
functionButton1.classList.add("set");
functionButton1.innerHTML = "SET";
functionButton2.classList.add("cancel");
functionButton2.innerHTML = "X";
functionButton3.classList.add("back");
}
function removeAlarmIcons() {
functionButton1.classList.remove("set");
functionButton1.innerHTML = "";
functionButton2.classList.remove("cancel");
functionButton2.innerHTML = "";
functionButton3.classList.remove("back");
}
function addInternetIcons() {
functionButton3.classList.add("back");
}
function removeInternetIcons() {
functionButton3.classList.remove("back");
}
function hideDoomsDay() {
doomSelect.forEach(function (inputItem) {
inputItem.classList.remove("show");
inputItem.classList.add("hide");
});
}
function showDoomsDay() {
doomSelect.forEach(function (inputItem) {
inputItem.classList.remove("hide");
inputItem.classList.add("show");
});
}
/*** END OF DISPLAY ***/
/*** ACKNOWLEDGEMENTS ***/
/* W3SCHOOLS */
Also see: Tab Triggers