title: Adapting my chat app to work with rooms in socket io
body: <p>So I have this simple chat application, and I'm looking to adapt it so the users can use the 4 different rooms I created.
  I'll try to explain how it works first, and I need to be guided, what would be the steps I need to take in order to make it work?(considering I'm a beginner) I've tried a lot of things but it always came out really buggy.</p>
  <p><strong>Client side:</strong></p>
  <pre><code>//Get the room name out of the URL and send it to the server
  function getRoomName() {
          let roomName = window.location.toString();
          if(roomName.includes('#') === true){
              roomName = roomName.split(&quot;#&quot;);
              roomName.splice(0, 1);
              roomName = roomName.toString();
              // Join room
              socket.emit('joinRoom', roomName);
          }
      }
  
  //Here I am changing the URL when clicking on a room button (I got one of these for each button)
  proiectFinalRoom.addEventListener('click', () =&gt;{
          window.location.href='#proiectFinal'; 
          roomNameEdit.innerHTML = &quot;#PROIECT-FINAL&quot;;  
      })
  
   sendBtn.addEventListener('click', () =&gt;{
          sendMessage();
      })
  
      //Here I am sending the message to the server
      function sendMessage(){
          if(messageInput.value === &quot;&quot;){
              return;
          } else {
                     //Calling the getRoomName function (when sending a message)
              getRoomName();
  
              const text = messageInput.value;
              socket.emit('message', text);
          displayMessage();
          }
      }
  </code></pre>
  <p><strong>Server side:</strong></p>
  <pre><code>io.on('connection', (socket) =&gt; {
      socket.on('joinRoom', function(roomName){
          //Join room
          socket.join(roomName);
  
          //Send messages
          socket.on('message', (message) =&gt; {
              socket.broadcast.to(roomName).emit('message', `${message}`);          
          });
      });
  });
  </code></pre>
  <p>This is the stage I am at right now, and It is definetely not working as it should. I already read a lot of articles about socket.io and rooms, but since english is not my first language I find it hard to understand where the problem is in my code.</p>