0

I have two functions. The first one changes some HTML elements, and the other one displays a confirmation message. The problem is that I need the confirmation message to appear after the HTML element is changed, but what actually happens is the opposite.

function playerMovment() {
  move = eval(k + turn + ".playerPostion") + diceValue
  // detrmine if a player complet one turn and add 200 money to him 
  if (move >= spaceNames.length) {
    move = move - spaceNames.length
    eval(k + turn + ".playerMony+=200")
  }
  // moving the player sympol to the new postion 
  $(".turn h3").remove();
  $("#" + spaceNames[eval(k + turn + ".playerPostion")] + " ." + colors[turn - 1]).remove();
  $("#" + spaceNames[move]).prepend(symboles[turn - 1]);
  // update the postion of the player 
  eval(k + turn + ".playerPostion" + "=" + move)
  //////////////////////////

}

function landowner() {
  currentPlayerPostion = eval(k + turn + ".playerPostion")
  currentSpace = spaceNames[currentPlayerPostion]
  spaceNotForSale = notForSale.includes(currentSpace);
  if (spaceNotForSale) {} else {
    if (player1.playerLand.includes(currentSpace)) {
      howOwnIt = 1;
    } else if (player2.playerLand.includes(currentSpace)) {
      howOwnIt = 2;
    } else if (player3.playerLand.includes(currentSpace)) {
      howOwnIt = 3;

    } else if (player4.playerLand.includes(currentSpace)) {
      howOwnIt = 4;
    } else {
      howOwnIt = 0
    }

    if (howOwnIt !== eval(k + turn)) {
      switch (howOwnIt) {
        case 1:
          player1.playerMony += 50;
          break;

        case 2:
          player2.playerMony += 50;
          break;

        case 3:
          player3.playerMony += 50;
          break;

        case 4:
          player4.playerMony += 50;
          break;

        case 0:
          buy = confirm("Would you like to buy this land?")
          break;
        default:

      }
    }
    if (buy) {
      eval(k + turn + ".playerLand").push(spaceNames[eval(k + turn + ".playerPostion")]);

    }
  }
}

function main() {
  rollDice();
  diceImg();
  playerMovment();
  landowner();
  playerTurn();

}

This is the code. I need the playerMovment function to be executed completely before the landOwner function.

Barmar
  • 741,623
  • 53
  • 500
  • 612

0 Answers0