title: Give 1 point to each unique winner respectively in javascript
body: <p>First of all, I hope you can understand my English. I'm not really good at English. I'd like to ask for help on giving 1 point to every unique user(a user that joined, a live stream to be exact)  for every correct answer.</p>
  <p>The issue I have in the current coding is that instead of giving points to each user respectively, it counts all users as one. What I mean by that is, for example: When user A wins, he gets(displays) 1 point. When user B wins, he gets(displays) 2 points. The points keep adding for every other user.</p>
  <p>I'd like it to be like this: When user A wins, he gets(displays) 1 point. When user B wins he also gets(displays) 1 point too. That means each user has their own winning record.</p>
  <p>I hope you can understand what I'm trying to explain.
  Please ask if you need further explanation on things you don't understand.</p>
  <p>I'd like to display the win count under/currently under the 'function addPhoto'.
  Following is the current code:</p>
  <p>Thanks in advance!</p>
  <pre><code>// DATA
  let connection = new TikTokIOConnection(undefined);
  let gameWords = [];
  let gamegameSelectedWord = null;
  let gameTimer = null;
  let gameStatus = false;
  let wins = 0;
  
  // Config
  let confComment = false;
  let confLike = false;
  let confShare = false;
  let confJoin = false;
  
  // START
  $(document).ready(() =&gt; {
      // Resize
      function resizeContainer() {
          let height = window.innerHeight;
          let width = Math.round((9 / 16) * height);
          $(&quot;#gameSize&quot;).html(width + 'x' + height);
          $(&quot;.container&quot;).outerWidth(width);
          $(&quot;.background&quot;).outerWidth(width);
          $(&quot;.printer&quot;).outerWidth(width);
          $(&quot;.animation&quot;).outerWidth(width);
  
          // Paper
          if (window.innerWidth &gt;= 1366) {
              var paperHeight = $(&quot;#paperContainer&quot;).outerHeight() - 20;
          } else {
              var paperHeight = $(&quot;#paperContainer&quot;).outerHeight() + 7;
          }
          $(&quot;#paper&quot;).outerHeight(paperHeight);
      }
      resizeContainer();
      $(window).resize(function() {
          resizeContainer();
      });
  
      // Connect
      $(&quot;#targetConnect&quot;).click(function(e) {
          // Check
          if (gameStatus) {
              let targetLive = $(&quot;#targetUsername&quot;).val();
              connect(targetLive);
          } else {
              alert(&quot;Start game first!&quot;);
          }
          
      });
  
      // Test
      $(&quot;#btnPrepare&quot;).click(function(e) {
          // Check sound
          playSound(1);
          playSound(2);
          playSound(3);
          playSound(4);
          speakTTS(MSG_TEST);
  
          // Populate dummy
          for (let i = 0; i &lt; 30; i++) {
              addContent(&quot;&lt;div style='text-align:center;'&gt;Welcome &lt;/div&gt;&quot;);
          }
  
          // Load game
          loadGame();
  
          // Setting
          loadSetting();
  
          // Set
          gameStatus = true;
      });
  
      // Save config
      $(&quot;#btnSave&quot;).click(function(e) {
          loadSetting();
      });
  })
  
  /*GAME PLAY
  */
  
  function speakTTS(msg) {
      speak(msg, {
          amplitude: 100,
          pitch: 70,
          speed: 150,
          wordgap: 5
      });
  }
  
  /*function scramble( s ) {
   return s.replace(
    /\b([a-z])([a-z]+)([a-z])\b/gi,
    function( t, a, b, c ) {
     b = b.split( /\B/ );
     for( var i = b.length, j, k; i; j = parseInt( Math.random() * i ),
      k = b[--i], b[i] = b[j], b[j] = k ) {}
     return a + b.join( '' ) + c;
    }
   );
  }
  document.forms.f.onsubmit = function() {
   this.elements.t.value = scramble( this.elements.t.value );
   return false;
  };
  document.forms.f.elements.t.value =
   scramble( gettext( document.getElementsByTagName( 'p' )[0] ) );
   */
  function censor(word) {
      let censored = [];
      let length = word.length;
      let target = Math.ceil(length / 2);
  
      let range_start = 2;
      let range_end = target;
  
      for (let i = 0; i &lt; length; i++) {
          let c = word.charAt(i);
          if (i &gt;= range_start &amp;&amp; i &lt;= range_end) {
              if (c === &quot; &quot;) {
                  censored.push(&quot;&amp;nbsp;&amp;nbsp;&quot;);
              } else {
                  censored.push(&quot;*&quot;);
              }
          } else {
              censored.push(c);
          }
      }
  
      return censored.join(&quot;&quot;);
  }
  
  function copyArray(a) {
      let b = [];
      for (i = 0; i &lt; a.length; i++) {
          b[i] = a[i];
      }
      return b;
  }
  
  function shuffle(a) {
      let j, x, i;
      for (i = a.length - 1; i &gt; 0; i--) {
          j = Math.floor(Math.random() * (i + 1));
          x = a[i];
          a[i] = a[j];
          a[j] = x;
      }
      return copyArray(a);
  }
  
  function countDown() {
      // Counter
      let timeleft = 60 * 4; // 4 Mins
  
      // Clear
      if (gameTimer != null) {
          clearInterval(gameTimer);
      }
  
      // Start
      gameTimer = setInterval(function() {
          // Reset
          if (timeleft &lt;= 0){
              clearInterval(gameTimer);
              loadGame();
          }
  
          // Set
          $(&quot;#gameTimeout&quot;).html(timeleft.toLocaleString() + &quot;s&quot;);
          timeleft -= 1;
  
      }, 1000);
  }
  
  function loadGame() {
      // Check
      if (gameWords.length &lt; 1) {
          gameWords = shuffle(WORDS);
      }
  
      // Load
      gameSelectedWord = gameWords.pop();
  
      // Set remain words
      $(&quot;#gameWords&quot;).html(gameWords.length);
  
      // Check
      if (typeof gameSelectedWord === 'string') {
          // Normalize
          splittedWord = gameSelectedWord.split(&quot;|&quot;);
          gameSelectedWord = splittedWord[1];
  
          // Set
          $(&quot;#textGuess&quot;).html(&quot;&lt;div style='font-size:70%;padding-bottom:5px;'&gt;&quot; + splittedWord[0] + &quot;&lt;/div&gt;&quot; + censor(gameSelectedWord));
          //$(&quot;#textGuess&quot;).html(&quot;&lt;div style='font-size:70%;padding-bottom:5px;'&gt;&quot; + splittedWord[0] + &quot;&lt;/div&gt;&quot; + scramble(gameSelectedWord));
  
          // Timeout
          countDown()
  
      } else {
          loadGame();
      }
  }
  
  function checkWinner(data, msg) {
      // Check type
      if (typeof gameSelectedWord === 'string' &amp;&amp; typeof msg === 'string') {
          // Check answer
          if (gameSelectedWord.trim().toLowerCase() == msg.trim().toLowerCase()) {
              // Print Photo
              addPhoto(data, &quot;winner&quot;);
  
              // Sound
              playSound(4);
  
              // Play TTS
              let tssMsg = MSG_WINNER.replace(&quot;|username|&quot;, data.uniqueId);
              speakTTS(tssMsg);
  
              // Reload game
              loadGame();
          }
      }
  }
  
  function loadSetting() {
      // Load
      confComment = $(&quot;#confComment&quot;).prop('checked');
      confLike = $(&quot;#confLike&quot;).prop('checked');
      confShare = $(&quot;#confShare&quot;).prop('checked');
      confJoin = $(&quot;#confJoin&quot;).prop('checked');
  }
  
  /*LIVE TIKTOK
  */
  
  function connect(targetLive) {
      if (targetLive !== '') {
          $('#stateText').text('Connecting...');
          $(&quot;#usernameTarget&quot;).html(&quot;@&quot;+targetLive);
          connection.connect(targetLive, {
              enableExtendedGiftInfo: true
          }).then(state =&gt; {
              $('#stateText').text(`Connected ${state.roomId}`);
          }).catch(errorMessage =&gt; {
              $('#stateText').text(errorMessage);
          })
      } else {
          alert('Enter username first!');
      }
  }
  
  function sanitize(text) {
      return text.replace(/&lt;/g, '&amp;lt;')
  }
  
  function isPendingStreak(data) {
      return data.giftType === 1 &amp;&amp; !data.repeatEnd;
  }
  
  function playSound(mode) {
      document.getElementById(&quot;sfx&quot;+mode).play();
  }
  
  function addContent(payload) {
      // Container
      let content = $('#paper');
      content.append(&quot;&lt;div class='item'&gt;&quot; + payload + &quot;&lt;/div&gt;&quot;);
  
      // Scroll top bottom
      content.animate({ scrollTop: content.get(0).scrollHeight}, 333);
  }
  
  function addMessage(data, msg) {
      // DATA
      let userName = data.uniqueId;
      let message = sanitize(msg);
  
      // Check for voice
      let command = message.split(&quot; &quot;)[0];
      if (command == &quot;:=say&quot; || command == &quot;:=cakap&quot;) {
          // TTS
          let cleanText = message.replace(&quot;=:say&quot;, &quot;&quot;).replace(&quot;=:cakap&quot;, &quot;&quot;);
          speakTTS(cleanText);
  
      } else {
          // Check setting
          if (confComment) {
              // Add
              addContent(&quot;&lt;span style='font-weight: bold;'&gt;&quot; + userName + &quot;&lt;/span&gt;: &quot; + message);
  
              // Sound
              playSound(1);
          }
          
      }
  }
      
  function addPhoto(data, mode) {
      // DATA
      let userName = data.uniqueId;
      let userAvatar = data.profilePictureUrl;
      let word = ['Nice going','That’s better than ever','That’s first class work','I’m impressed','Nothing can stop you now','Well done','Good job','You did it','That’s the way','You rock','I knew you could do it','Keep up the good work','That’s clever','Way to go','Outstanding','Tremendous','Fantastic','You are amazing','No one can beat you','You are the chosen one'];
      let words = word[Math.floor(Math.random()*word.length)];
  
      // Add
      if (mode == &quot;winner&quot;)
          {
          wins++;
          addContent(
              `&lt;div style=&quot;text-align:center;font-size: 1.25rem;&quot;&gt;
                  &lt;div style='padding-bottom:.25rem;color:#1881FF;'&gt; `+words+`&lt;/div&gt;
                  &lt;div style='padding-bottom:.5rem;font-weight: bold;color:#20B601;'&gt;`+userName+` ❗&lt;/div&gt;
                  &lt;div&gt;
                      &lt;img src=&quot;`+userAvatar+`&quot; style=&quot;width:135px;height:135px;border-radius: 15px;&quot;/&gt;
                      Wins: `+wins+`
                  &lt;/div&gt;
              &lt;/div&gt;`
          );
      } else {
          addContent(
              `&lt;div style=&quot;text-align:center;font-size: 1.25rem;&quot;&gt;
                  &lt;div style='padding-bottom:.25rem;'&gt;Thanks&lt;/div&gt;
                  &lt;div style='padding-bottom:.5rem;font-weight: bold;color:#EA0C0C;'&gt;`+userName+`&lt;/div&gt;
                  &lt;div&gt;
                      &lt;img src=&quot;`+userAvatar+`&quot; style=&quot;width:135px;height:135px;border-radius: 15px;&quot;/&gt;
                  &lt;/div&gt;
              &lt;/div&gt;`
          );
      }
  
      // Sound
      playSound(3);
  }
  
  function addGift(data) {
      // DATA
      let userName = data.uniqueId;
      let giftPictureUrl = data.giftPictureUrl;
      let giftName = data.giftName;
      let giftRepeat = data.repeatCount;
      let giftTotal = (data.diamondCount * data.repeatCount);
      let word = ['Appreciate it','Thanks','Thank you very much','It means a lot','You’re the best','Your gift helps me',];
      let words = word[Math.floor(Math.random()*word.length)];
  
      // Check
      if (giftTotal &gt;= 10) {
          // Print Photo
          addPhoto(data);
  
      } else {
          // Add
          addContent(
              `&lt;div style=&quot;text-align:center;font-size: 1.25rem;&quot;&gt;&lt;div style='padding-bottom:.5rem;'&gt;`+words+` &lt;span style='font-weight: bold;color:#EA0C0C;'&gt;`+userName+`!&lt;/span&gt;&lt;/div&gt;
              &lt;div style='font-weight: bold;padding-bottom:.5rem;'&gt;&lt;img src=&quot;`+giftPictureUrl+`&quot; style=&quot;width:35px;height:35px;&quot;/&gt; Sent `+giftName+`&lt;/div&gt;
              x`+giftRepeat.toLocaleString()+` worth `+giftTotal.toLocaleString()+` coins!&lt;/div&gt;`
          );
  
          // Sound
          playSound(2);
  
          // Play TTS
          let tssMsg = MSG_GIFT.replace(&quot;|username|&quot;, userName);
          speakTTS(tssMsg);
      }
  }
  
  // New chat comment received
  connection.on('chat', (data) =&gt; {
      addMessage(data, data.comment);
      checkWinner(data, data.comment);
  })
  
  // New gift received
  connection.on('gift', (data) =&gt; {
      if (!isPendingStreak(data) &amp;&amp; data.diamondCount &gt; 0) {
          addGift(data);
      }
  })
  
  // Like
  connection.on('like', (data) =&gt; {
      if (typeof data.totalLikeCount === 'number') {
          // Check setting
          if (confLike) {
              // Print like
              addMessage(data, data.label.replace('{0:user}', '').replace('likes', `${data.likeCount} likes`));
          }
      }
  })
  
  // Share, Follow
  connection.on('social', (data) =&gt; {
      // Check setting
      if (confShare) {
          // Print share
          addMessage(data, data.label.replace('{0:user}', ''));
      }
  })
  
  // Member join
  let joinMsgDelay = 0;
  connection.on('member', (data) =&gt; {
      let addDelay = 250;
      if (joinMsgDelay &gt; 500) addDelay = 100;
      if (joinMsgDelay &gt; 1000) addDelay = 0;
  
      joinMsgDelay += addDelay;
  
      setTimeout(() =&gt; {
          joinMsgDelay -= addDelay;
          // Check setting
          if (confJoin) {
              // Print join
              addMessage(data, &quot;has entered&quot;);
          }
      }, joinMsgDelay);
  })
  
  // End
  connection.on('streamEnd', () =&gt; {
      $('#stateText').text('Stream ended.');
  })
  
  </code></pre>