title: Firebase JavaScript value Change Events
body: <p>I am wondering how i can solve the following issue. I have a Record in the Firebase DB which i am monitoring. The App is a Sports Score So far so good.
  When user loads the initial page i check if Game is Running or Stopped and so a few things.
  below is a snipped of what i do</p>
  
  <pre><code>if(Clock.Status=='Running'){
              ......
          }
          else if(Clock.Status == 'Stopped'){
              .......
          }
  </code></pre>
  
  <p>So far so good when user hits the page for first time. But now i want to monitor if the ClockStatus changes</p>
  
  <pre><code>clockStatusRef = firebase.database().ref("games/"+gameId+"/Score/");
  clockStatusRef.on("child_changed", function(snapshot) {
      var Clock = snapshot.val();
      var status = Clock.Status;
  
      // clock stopped - second scenario
      if(status=='Stopped'){
          stopTimer();
      }
      else if(status == 'Running'){
          // clock status running- third scenario
          firebase.database().ref('/.info/serverTimeOffset')
                .once('value')
                .then(function stv(data) {
                  console.log('hi');
                  serverTime = (data.val() + Date.now())/1000;
                  var timeElapsed = serverTime - Clock.ClockStart;
                  var totalCounts    = document.getElementById("total_counts");
                  if(Clock.Timer &gt; timeElapsed){
                      initTimer(Math.floor(Clock.Timer- timeElapsed),60);
                  }
                  else{
                      var Current_Clock = document.getElementById("count");
                      Current_Clock.innerHTML = '00:00';
                  }
                }, function (err) {
                  return err;
                });
      }
      console.log("Clock status changed: "+status);
  
  });
  </code></pre>
  
  <p>for some strange reason on a change of status it starts with the main if </p>
  
  <pre><code>if(Clock.Status=='Running')
  </code></pre>
  
  <p>So i am wondering what am i missing and what is the best way to fix this so the first if is only run on the initial load and all subsequent will use the if's which handle status change of clock.</p>
  
  <p>Here is the Json for <code>games/B8120ACD-DF51-A64A-A83E-556007522E80/Score/Clock</code></p>
  
  <pre><code>{
    "ClockStart" : 1510535632, 
    "Period" : 1, 
    "Status" : "Stopped", 
    "Timer" : 900 
  }
  </code></pre>