-4

Problem: detectLocationtimersset() logic does not seem to work. I know the sub routine is fired but I guess the multiple if else is wrong ?

The the reason for detectLocationtimersset() was to have some logic to ensure multiple timers are not set.

I created the 1st if / else to set the timers based on datatime first then I wrote a second if / else to do the sense check.

detectLocation() has been tested and works in its own right.

var detectLocationtimerset = 0;
var datatime = 1;

function detectLocationtimersset() {    
    // Setup timer to check for new data start
    // check and see if set 
    if (detectLocationtimerset = 0 ) {
        detectLocationtimerset = 1;
        if (datatime == null) {
            datatime = 9;
            milliseconds = (datatime * 60000)
            setInterval(function () {
                detectLocation();
                console.log("detectLocation() timer set");
            }, milliseconds);   
        } else {
                    detectLocationtimerset = 1;
            milliseconds = (datatime * 60000)
            setInterval(function () {
                detectLocation();
                console.log("detectLocation() timer set");
            }, milliseconds);   
        }   
    }
};
Terran Brown
  • 509
  • 10
  • 25

2 Answers2

4

I don't know what the problem is, but

if (detectLocationtimerset = 0 )

should probably be

if (detectLocationtimerset === 0)

On other notes,

  • your indentation should be consistent
  • your spacing around operators should be consistent
  • you should prefer identity over equality wherever possible
  • you should move shared code out of the if/else block — put the milliseconds assignment and setInterval call after the if (datatime == null) block
Community
  • 1
  • 1
Waleed Khan
  • 11,426
  • 6
  • 39
  • 70
2

Your

if (detectLocationtimerset = 0 ) {

should be

if (detectLocationtimerset === 0 ) {
asgoth
  • 35,552
  • 12
  • 89
  • 98