27 日が期限のプロジェクトがあるのですが、問題が発生しました。Repl.it は、プログラムを起動するたびにクラッシュします。私のコードを見ると、42 行目:
//getting a number that isnt the players door or the prize door
while ((randomDoor2 == prizeDoor) || (randomDoor2 == randomDoor)) {
setTimeout(
function(){
randomDoor2 = Math.round(random(1,3));
},
10000);
}
while ループがあります。それをコメントアウトすると、コードは遅れることなく完全に機能します。
何を試して何をすべきかわかりません。
それは私のwhile以外のものかもしれないので、ここに私のscript.js全体があります:
var chance; // swap | dont swap
var prizeDoor;
var randomDoor;
var randomDoor2;
var randomDoor3;
var decide;
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
var chance = 50; // swap | dont swap
var prizeDoor;
var randomDoor;
var randomDoor2;
var randomDoor3;
var decide;
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)) {
setTimeout(
function(){
randomDoor2 = Math.round(random(1,3));
},
10000);
}
//showing this to the user
console.log("");
console.log("Door #" + randomDoor2 + " does not have the prize.");
//having the computer make a desicion
if (random(0,100) < chance) {
decide = "swap doors.";
while ((randomDoor3 !== randomDoor2) || (randomDoor3 !== randomDoor)) {
randomDoor3 = Math.round(random(1,3));
}
} else {
decide = "keep the current door.";
}
//letting the user know of the computer's desicion
console.log("");
console.log("The AI chose to " + decide);
// figuring out if the AI won
if (randomDoor3 == prizeDoor || randomDoor == prizeDoor) {
console.log("AI won!");
if (decide == "swap doors.") {
chance -= 5;
} else {
chance += 5;
}
} else {
console.log("AI lost.");
if (decide == "swap doors.") {
chance += 5;
} else {
chance -= 5;
}
}
}
while ステートメントで、選択されたドアでも賞品のあるドアでもないドアを見つけるようにしたかったのですが、代わりにクラッシュしました。