$(document).ready(function () {
var hour = $('#hour'),
minute = $('#minute'),
second = $('#second'),
timerHours = $('#timerHours'),
timerMinutes = $('#timerMinutes'),
timerSeconds = $('#timerSeconds'),
setTimer = $('#setTimer'),
timerIsOn = $('#on'),
alarmBox = $('#alarm'),
now = new Date(),
alarm = {
hasBeenSet: false,
aHour: 0,
aMinute: 0,
aSecond: 0
},
timer;
setInterval(function () {
// Get current time
now = new Date();
// Set current time
hour.text(now.getHours());
minute.text(now.getMinutes());
second.text(now.getSeconds());
// Check weither the alarm should fire
if (alarmIsFired()) {
fireAlarm();
}
}, 1000);
setTimer.click(function () {
// Different function depending on wether the alarm has fired
if (alarmIsFired()) {
// Show that timer is off
timerIsOn.css("opacity", "0");
// Inform that alarm is no longer active
alarm.hasBeenSet = false;
console.log('alarm on/off : ', alarm.hasBeenSet);
} else {
// Set alarm time
alarm.aHour = timerHours.val();
alarm.aMinute = timerMinutes.val();
alarm.aSecond = timerSeconds.val();
// Inform that alarm has been set
alarm.hasBeenSet = true;
// Show that timer is on
timerIsOn.css("opacity", "1");
}
});
function fireAlarm() {
var isBig = false;
console.log('alarm', alarm);
if (alarm.hasBeenSet) {
alarmBox.css("opacity", "1");
setTimer.text("Shut off alarm");
timer = setInterval(function () {
console.log('hit');
if (isBig) {
alarmBox.css("width", "900px");
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.