can't change variable value javascript
<p>So I'm working on a script that will save every second a person was online on whatsapp (on whatsapp web) </p>

<p>and I have this:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>//add zeros (run only once)
function addZero(i) {
  if (i &lt; 10) {
    i = "0" + i;
  }
  return i;
}

//Inject jQuery (run only once)
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);

// make online log
//start
var online = "yes";
var onlineCheck1 = window.setInterval(function() {
  var x = $('#main&gt;header&gt;div.chat-body&gt;div.chat-status&gt;span').text()
  var name = $('#main&gt;header&gt;div.chat-body&gt;div.chat-main&gt;.chat-title&gt;span').text()
  var d = new Date();
  if (x == "online") {
    var online = "yes";
    console.log(d.toLocaleDateString('en-GB') + "|" + addZero(d.getHours()) + ":" + addZero(d.getMinutes()) + ":" + addZero(d.getSeconds()) + " " + name + " " + "was" + " " + "///online///");
  } else if (online == "yes") {
    console.log("&lt;------------&gt;")
    var online = "no";
  } else {
    var online = "no";
  }

}, 1000); //end</code></pre>
</div>
</div>
</p>

<p>and it's logging when someone is online but I want it to put just one mark (&lt;------------>) when the person is offline and it's not doing that.</p>

<p>so what I want this script to do is:<br> make the variable "online" with the value "yes" <br> then make the variable "x" with the value the inner text of an element (which is online or last seen.....) <br>and then look if x is online? then change the value of "online" to "yes" log the date and time<br> if not and if the value of the variable "online" is "yes"? then log a mark (&lt;------------>) and change the value of "online" to "no" <br>if not? then just change the value of the variable "online" to "no" and repeat.<br>
I don't know what is going wrong but it may be that the variables are not getting changed for some reason.
<br><br>
Note: i'm using chrome's console to run this script on web.whatsapp.com so you can try it if you want to see what I mean.</p>