Stopwatch App is for Android. I am using Titanium Studio and JavaScript. I am trying to make my "Stop" button to perform another action. I want it to resume the time. I am also trying to make my "Lap" button work. Why doesn't my event listener fire for both the "Stop" and "Lap" buttons? I know this is very basic code, but programming is not my strongest point..."button03" is the STOP button, and "button04" is the LAP button. Any help will be appreciated. I have attached parts of my code below that is relevant to my question. Thanks.
var _startStopwatch = function() { timerlabel.value = '00:00:00.0'; var startTime = new Date(); var _updateTimer = function updateTimer() { var UNIT_HOUR = 60 * 60 * 1000; var UNIT_MINUTE = 60 * 1000; var UNIT_SEC = 1000; var now = new Date(); var diff = now.getTime() - startTime.getTime(); var hour = Math.floor(diff / UNIT_HOUR); var minute = Math.floor((diff - hour * UNIT_HOUR) / UNIT_MINUTE); var sec = Math.floor((diff - hour * UNIT_HOUR - minute * UNIT_MINUTE) / UNIT_SEC); var msec = Math.floor(diff % UNIT_SEC); timerlabel.text = ('0' + hour).slice(-2) + ':' + ('0' + minute).slice(-2) + ':' + ('0' + sec).slice(-2) + '.' + ('00' + msec).slice(-1); }; intervalid = setInterval(_updateTimer, 3); button03.title = 'STOP'; }; var _stopStopwatch = function() { clearInterval(intervalid); }; var started = false; var intervalid = null; var resume = true; button03.addEventListener("click", function(e){ if (started) { _stopStopwatch(); started = false; } else { resume = true; } }); //NOT FUNCTIONING. button04.addEventListener("click", function(e) { if (button01 == null | button03 == null) { return 'Undefined'; } else { return(button03 - button01) / 1000; } });
2 Answers
hey dude :D
sorry wrong person.
Your Answer
Think you can help? Login to answer this question!