The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript setInterval only output message once if changed

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
  • #239824

    Hello, I am checking a JSON every x seconds to see if a specific thing has changed in it. This change will determine if a specific someone on has gone live. Once they do go live, it’ll output a console log saying they’ve went live and when they go offline.

    Currently, it repeats the live or offline message. I need it to only output the status message once. How do I do this? This is my current code.

    var twitch = '';
        var online = false
        setInterval(function() {
          checkStream(twitch, function(data) {
            data = JSON.parse(data)
            if ( && !online) {
              online = true
              console.log(`Mattypocket is online, playing ${}.`)
            } else {
              online = false
        }, 1000);
        function checkStream(url, callback) {
          request(url, function(err, response, body) {
            if (!err && response.statusCode == 200) {
              if (callback && typeof callback === "function") {
Viewing 1 post (of 1 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.