我有一个计划于27日到期的项目,而且我有一个奇怪的小故障。从代码中可以看到,我有一个while循环,它根据某些条件设置变量。但是,如果您查看控制台,它会不断说变量是相同的,无论它依赖的变量有多大。
这是我的整个代码:
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.");
}
P.S。这段代码是用repl.it编写的,它忽略了Java的分号。
P.S.S。我竭尽全力寻找这种情况的克隆,但是我发现没有一种可以解决我遇到的故障。