var currentTimeArray = [];
function currentTime(){
var time = moment();
return currentTimeArray.push(time);
}
$('.next-fieldgroup').on('click', function(e){
e.preventDefault();
currentTime();
var endTime = $(currentTimeArray).last();
var startTime = currentTimeArray[0];
var duration = moment.duration(endTime.diff(startTime));
var elapsedTime = duration().asMinutes();
$('#timer-counter').text( elapsedTime );
});
What it is supposed to do...
- on click store NOW time in to ARRAY
- on click compare arr[0] with arr.last() to get time elapsed time
- update div with elapsed time in minutes
I expect the output to like:
"Time elapsed: 12 minutes"
I get the following error:
Uncaught TypeError: undefined is not a function