我正在尝试编写一个石头剪刀游戏。当我单击我的输入时,不会调用该函数。我想知道我是否在我的代码中忽略了任何内容:
function LFG(){
var c=math.random();
if (c<0.3333){
cmove="r";
document.getElementById("playahater").src("rightRockHand.jpg");
}
if (c>0.3333 && c<0.6666){
cmove="p";
document.getElementById("playahater").src("rightHandPaper.jpg");
}
if (c>0.6666){
cmove="s";
document.getElementById("playahater").src("rightHandScissors.jpg");
}
return cmove;
}
function rock(){
LFG();
document.getElementById("playa").src("leftRockHand.jpg");
if (cmove == "r"){
ties += ties;
return ties;
}
if (cmove == "p"){
losses += losses;
return losses;
}
if (cmove == "s"){
wins += wins;
return wins;
}
}
此代码涵盖了我的所有功能,切换了纸张和剪刀的逻辑替代品的第二个功能。这是调用函数的地方
<td><input onclick="scissor()" type="image" src="scissors.jpg" alt="scissors" id="scissors"/></td>
答案 0 :(得分:0)
function rock(){
var cmove = LFG(); <-- here is your fix
document.getElementById("playa").src("leftRockHand.jpg");
if (cmove == "r"){
ties += ties;
return ties;
}
if (cmove == "p"){
losses += losses;
return losses;
}
if (cmove == "s"){
wins += wins;
return wins;
}
}