我正在尝试使剪刀布游戏正常工作。我正在JavaScript
中进行,它是用于学校作业。当我运行游戏并尝试单击石头或剪刀图像之一时,它会在调试控制台中显示它已被单击。但是我不希望它执行的操作。我该怎么办?
// Numbers are being assigned to the variables of the computer and the computer's choice.
var compChoice1 = randomNumber(0, 1);
var compChoice2 = randomNumber(0, 1);
var compChoice3 = randomNumber(0, 1);
var compChoice = computer;
if (compChoice1 <= 0.3) {
compChoice1 = "scissorsImage";
}
if (compChoice2 >= 0.6) {
compChoice2 = "rockImage";
}
if (compChoice3 == (0.4 || 0.5)) {
compChoice = "paperImage";
}
// Values are being assigned to the variables of the user's choice.
var scissorsChoice = [0, 0.1, 0.2, 0.3];
var rockChoice = [0.6, 0.7, 0.8, 0.9, 1];
var paperChoice = [0.4, 0.5];
// If the rock is clicked, the user will be taken to tie, lose, or win screen depending on the
// computer's choice.
onEvent("rockImage", "click", function( ) {
if (rockChoice == "scissorsChoice") {
setScreen("youWin");
} else {
if (rockChoice == "rockChoice") {
setScreen("tieScreen");
onEvent("backToStart", "click", function( ) {
setScreen("welcomeScreen");
});
}
}
if (rockChoice == "paperChoice") {
setScreen("youLose");
onEvent("startOver2", "click", function( ) {
setScreen("welcomeScreen");
});
}
});
// If the paper is clicked, the user will be taken to tie, lose, or win screen depending on the
// computer's choice.
onEvent("paperImage", "click", function( ) {
if (paperChoice == "scissorsChoice") {
setScreen("youLose");
} else {
if (paperChoice == "rockChoice") {
setScreen("youWin");
}
}
if (paperChoice == "paperChoice") {
setScreen("tieScreen");
}
});
// If the scissors are clicked, the user will be taken to tie, lose, or win screen depending on the
// computer's choice.
onEvent("scissorsImage", "click", function( ) {
if (scissorsChoice == "scissorsChoice") {
setScreen("tieScreen");
} else {
if (scissorsChoice == "rockChoice") {
setScreen("youLose");
}
}
if (scissorsChoice == "paperChoice") {
setScreen("youWin");
}
});