0

I have a project that is due on the 27th, and I have a strange glitch. As you can see from the code, I have a while loop that sets a variable based on certain conditions. But if you look at the console, it keeps on saying that the variable is the same, no matter how different the variables it depends on are.

This is my entire code:

var chance; // dont swap  |  swap
var prizeDoor;
var randomDoor;
var randomDoor2;

function setup() {
  chance = 50;
  createCanvas(1000, 1000);
}

function draw() {
  //setting up round

  prizeDoor = Math.round(random(1, 3));

  //choosing first door

  console.log("[1] [2] [3]");
  randomDoor = Math.round(random(1, 3));

  //showing user the door AI picks

  if (randomDoor == 1) {
    console.log(" ^");
    console.log(" |");
  } else if (randomDoor == 2) {
    console.log("     ^");
    console.log("     |");
  } else {
    console.log("         ^");
    console.log("         |");
  }

  console.log("AI chooses door #" + randomDoor + ".");

  //revealing a door

  //getting a number that isnt the players door or the prize door
  while ((!randomDoor2 == prizeDoor) || (!randomDoor2 == randomDoor)) {
    randomDoor2 = Math.round(random(1, 3));
  }

  //showing this to the user
  console.log("");
  console.log("Door #" + randomDoor2 + " does not have the prize.");
}
Ateur Games
  • 79
  • 1
  • 11
  • did you mean `randomDoor2 !== prizeDoor` ? – Bibberty Mar 20 '19 at 23:22
  • Yes, and that actually solved it. Thanks. – Ateur Games Mar 20 '19 at 23:23
  • Just realized you said `!==` instead of `!=`. Was this intentional? – Ateur Games May 19 '19 at 17:12
  • This is documented here: https://stackoverflow.com/questions/359494/which-equals-operator-vs-should-be-used-in-javascript-comparisons. But yes I meant `!==`. You should use `===` syntax wherever possible. Using `==` or `!=` can easily lead to unintended behavior and bugs in your code. – Bibberty May 21 '19 at 17:13

0 Answers0