title: do while loop not functioning and my code running infinite loop when i refresh
body: <p>the switch case is working except case case &quot;fas fa-random&quot; on musicAudio addEventListener ended, whenever the music ended, it will not select random song. if i refresh the page it will go into infinite loop</p>
  <p>html</p>
  <pre><code>&lt;audio id=&quot;main-audio&quot; src=&quot;&quot;&gt;&lt;/audio&gt;
  </code></pre>
  <p>javascript</p>
  <pre><code>let musicIndex = 1;
  repeatBtn.addEventListener('click', (e) =&gt; {
  const getClass = repeatBtn.className;
  switch(getClass){
      case &quot;fas fa-redo&quot;:
          repeatBtn.className = &quot;fas fa-random&quot;;
          repeatBtn.setAttribute(&quot;title&quot;, &quot;Playlist Shuffle&quot;)
      break;
          break;
      case &quot;fas fa-random&quot;:
          repeatBtn.className = &quot;fas fa-stop-circle&quot;;
          repeatBtn.setAttribute(&quot;title&quot;, &quot;Song Repeat&quot;)
      break;
      case &quot;fas fa-stop-circle&quot;:
      repeatBtn.className = &quot;fas fa-redo&quot;;
      repeatBtn.setAttribute(&quot;title&quot;, &quot;Song Looped&quot;)
      break;
  }
  })
  
  musicAudio.addEventListener('ended', () =&gt; {
  
  const getClass = repeatBtn.className;
  switch(getClass){
      case &quot;fas fa-random&quot;:
          let randIndex = Math.floor(Math.random() * allMusic.length) + 1;
          do{
              Math.floor(Math.random() * allMusic.length) + 1;
          }while(musicIndex = randIndex);
          const test = musicIndex = randIndex;
          loadMusic(musicIndex);
          playMusic();
          break;
      case &quot;fas fa-stop-circle&quot;:
          musicAudio.currentTime = 0;
          loadMusic(indexNumb)
          break;
      case &quot;fas fa-redo&quot;:
          nextMusic()
          break;
  }
  })
  </code></pre>