Stopwatch button help

You must Login before you can answer or comment on any questions.

Stopwatch App is for Android. I am using Titanium Studio and JavaScript. I am trying to make my "Start" button perform another action. I want it to resume the time (after it has been stopped). I am also trying to make my "Lap" button work. The event listener does fire, but I want it to perform another action. Everything else works fine. I know this is very basic code and is probably an easy fix, but we all have our weak points."Button01" is the START 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();
 
intervalid = setInterval(_updateTimer, 1000);
    button03.title = 'STOP';
    };
 
    var _stopStopwatch = function() {
        clearInterval(intervalid);
    };
 
    var started = false;
    var intervalid = null;
    var resume = true;
 
//START BUTTON
button01.addEventListener("click", function(e){
    if (!started) {
        _startStopwatch();
        started = true;
      }
});
 
//RESET BUTTON
button02.addEventListener("click", function(e){
    if (started) {
        _stopStopwatch();
        started = false;
    }
    timerlabel.text = '00:00:00.0'; 
});
 
//STOP BUTTON
button03.addEventListener("click", function(e){
    if (started) {    
        _stopStopwatch();
        started = false;
    }
});
 
//LAP BUTTON NOT FUNCTIONING.
button04.addEventListener("click", function(e) {
    if (button01 == null | button03 == null) {
        return 'Undefined';
    } else {
        return(button03 - button01) / 1000;
    }
});

— asked 8 months ago by Bruce Ruffalo
3 Comments
  • My friend and I have asked this question before and we haven't gotten any help yet. If someone can please help us solve it or even guide us, we can move on to completing the rest of it.

    — commented 8 months ago by Bruce Ruffalo

  • Then if you asked the same question before, why posting it again and expecting a different results? It only makes the whole site less readable, thus making it less enjoyable for everybody.

    — commented 8 months ago by Christian Brousseau

  • I'm not expecting different results. I just want a little help and I know this is very basic code but programming is not my piece of cake.

    — commented 8 months ago by Bruce Ruffalo

2 Answers

Before anybody wastes any more time with this poster, please look at this thread.

In the previous thread, he wanted the Start button to only start the timer. I helped him do that.

Now he wants it to start the timer or resume it. There's no evidence he even tried to do anything to make that happen. He changed his mind about what he wants it to do, so he posted here to try to get somebody to write it for him.

This is really frustrating, and I suppose it's one of the downfalls of Titanium - somebody is marketing this as "mobile app development for beginners". Too many people in Q&A are here with absolutely no programming foundation whatsoever.

Titanium Mobile is:

  • easy to use for quick-and-dirty iOS applications

  • hard to use really well and cross platform

  • impossible to use for non-programmers

If you can't program your way out of a paper bag, please first learn how to program, then come take a crack at Titanium Mobile.

— answered 8 months ago by Jason Priebe
answer permalink
2 Comments
  • Thanks Jason for this info....

    — commented 8 months ago by Ashish Nigam

  • Okay listen here, Jason. Firstly, I appreciated your help the first time. I have given it a try but it was wrong that is why I didn't include the code in the question. As you can see in the code I declared var resume = true; and I was going to use that in the Start button to resume the time. Initially, I was going to do this with resuming the time:

    button01.addEventListener("click", function(e){
        if (!started) {
            _startStopwatch();
            started = true;
          } else {
        resume = true;
    }
    });
    That didn't work and that's why I'm coming here to ask. Also, I am not trying to get somebody to write it for me, I just want some assistance or guidance. I just started to learn programming a few months ago, so obviously I'm not an expert at it yet.

    — commented 8 months ago by Bruce Ruffalo

Hi Bruce,

can you explain a little bit more here, what is this kind of code...

else {
        return(button03 - button01) / 1000;
    }
in button04 eventlistener...

— answered 8 months ago by Ashish Nigam
answer permalink
1 Comment
  • Hi Ashish,

    That code is for the Lap button trying to track the elapsed time when it is pressed. It most likely is a wrong piece of code to do that but I gave it a go. Again, programming, not my strongest point...we all have our weaknesses.

    — commented 8 months ago by Bruce Ruffalo

Your Answer

Think you can help? Login to answer this question!