function showOnlineUsers(users) {

  var output = "<table id='playerDetails' cellspacing = '15' align = 'center'>";

  var fullname = localStorage.getItem("fullname");
  //Cycle through all users
  for (user of users.allUsers) {

    if (user.id < 2) {
      $(`#tableHeading`).text(`Waiting for another player to come online`);
    } else {
      $(`#tableHeading`).hide();
    }

    disabled = "disabled";
    fn = user.firstName + " " + user.lastName;

    var Player1 = user.id;
    var nameWithoutSpace = user.firstName + user.lastName;

    var chosenPlayer = user.id;
    if (fullname != fn) {
      output += `<tr>
                  <td>${user.firstName}</td>
                  <td>${user.lastName}</td>
                  <td><button type="button" class="availability" data-id="${chosenPlayer}">PLAY</button></td>
                </tr>`;
    }

    $(`#cp`).text(fullname);
    output = output + "</table>"
    $(`#onlinePlayersTable`).html(output);

    //If player click on `play` they are entered into a game
    $('.availability').on('click', function () {
      var chosenPlayerId = $(this).data('id');
      // If the second player clicks, they have already been entered into a game
      if (player2ID != myId) {
        enterPlayersIntoBoard(chosenPlayerId)
      }
      $(`#onlinePlayers`).hide();
      $(`#onlinePlayersTable`).hide();
      $(`.gamePlay`).show();

    });

  }

  //Sending names of player 1 and player 2 of the game
  fetch('/changePlayerName', {
      method: 'POST',
      headers: new Headers({
        'Content-Type': 'application/json'
      }),
      body: JSON.stringify({
        fullname,
        fn
      })
    })
    .catch(err => console.log(err));
}
/**
 * @function showOnlineUsers - Display online users who have logged in. Does not display one's own name.
 */
@function showOnlineUsers - Display online users who have logged in. Does not display one's own name.
@function showOnlineUsers - Display online users who have logged in . Does not display one ' s own name .
function showOnlineUsers(users) {
  var output = "<table id='playerDetails' cellspacing = '15' align = 'center'>";
  var fullname = localStorage.getItem("fullname");
  for (user of users.allUsers) {
    if (user.id < 2) {
      $(`#tableHeading`).text(`Waiting for another player to come online`);
    } else {
      $(`#tableHeading`).hide();
    }
    disabled = "disabled";
    fn = user.firstName + " " + user.lastName;
    var Player1 = user.id;
    var nameWithoutSpace = user.firstName + user.lastName;
    var chosenPlayer = user.id;
    if (fullname != fn) {
      output += `<tr>
                  <td>${user.firstName}</td>
                  <td>${user.lastName}</td>
                  <td><button type="button" class="availability" data-id="${chosenPlayer}">PLAY</button></td>
                </tr>`;
    }
    $(`#cp`).text(fullname);
    output = output + "</table>"
    $(`#onlinePlayersTable`).html(output);
    $('.availability').on('click', function () {
      var chosenPlayerId = $(this).data('id');
      if (player2ID != myId) {
        enterPlayersIntoBoard(chosenPlayerId)
      }
      $(`#onlinePlayers`).hide();
      $(`#onlinePlayersTable`).hide();
      $(`.gamePlay`).show();
    });
  }
  fetch('/changePlayerName', {
      method: 'POST',
      headers: new Headers({
        'Content-Type': 'application/json'
      }),
      body: JSON.stringify({
        fullname,
        fn
      })
    })
    .catch(err => console.log(err));
}
function showOnlineUsers ( users ) { var output = "<table id='playerDetails' cellspacing = '15' align = 'center'>" ; var fullname = localStorage . getItem ( "fullname" ) ; for ( user of users . allUsers ) { if ( user . id < 2 ) { $ ( ` ` ) . text ( ` ` ) ; } else { $ ( ` ` ) . hide ( ) ; } disabled = "disabled" ; fn = user . firstName + " " + user . lastName ; var Player1 = user . id ; var nameWithoutSpace = user . firstName + user . lastName ; var chosenPlayer = user . id ; if ( fullname != fn ) { output += ` ${ user . firstName } ${ user . lastName } ${ chosenPlayer } ` ; } $ ( ` ` ) . text ( fullname ) ; output = output + "</table>" $ ( ` ` ) . html ( output ) ; $ ( '.availability' ) . on ( 'click' , function ( ) { var chosenPlayerId = $ ( this ) . data ( 'id' ) ; if ( player2ID != myId ) { enterPlayersIntoBoard ( chosenPlayerId ) } $ ( ` ` ) . hide ( ) ; $ ( ` ` ) . hide ( ) ; $ ( ` ` ) . show ( ) ; } ) ; } fetch ( '/changePlayerName' , { method : 'POST' , headers : new Headers ( { 'Content-Type' : 'application/json' } ) , body : JSON . stringify ( { fullname , fn } ) } ) . catch ( err => console . log ( err ) ) ; }
@function showOnlineUsers - Display online users who have logged in.
@function showOnlineUsers - Display online users who have logged in .
//Cycle through all users //If player click on `play` they are entered into a game // If the second player clicks, they have already been entered into a game //Sending names of player 1 and player 2 of the game