-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
34 lines (33 loc) · 1.05 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
$(function() {
var alarms = [];
var audio = new Audio('alarm1.mp3');
var time = moment();
$('.clock-container').text(time.format('h:mm:ss a')).addClass('clock');
var myFunc = function(){
time = moment();
var currentTime = function(location, className){
$(location).text(time.format('h:mm:ss a')).addClass(className);
};
currentTime('.clock-container', 'clock');
alarms.forEach(function(val){
var diff = time.diff(val, 'seconds');
if(diff === 1){
audio.play();
}
})
};
window.check = setInterval(function(){
myFunc();
}, 1000);
$('button').on('click', function(){
var userHours = $('input.time')[0].valueAsNumber;
var userMinutes = $('input.time')[1].valueAsNumber;
var userAM = $('input.time')[2].checked;
var userPM = $('input.time')[3].checked;
var dayTime = !!userAM ? "AM" : "PM";
var alarmTime = userHours + ':' + userMinutes + dayTime;
var alarmMoment = moment({hour: userHours, minute: userMinutes})
alarms.push(alarmMoment);
$('.user-alarm').text(alarmTime);
});
});