在以下代码中:
我也试过传递whatThrow一个参数。我似乎没有发现什么是错的。
var ranThrow = ["empty", "rock", "paper", "scissors"];
var ranNum = Math.random();
var postRanNum = (ranNum * 3) + 1;
var roundPostRanNum = Math.floor(postRanNum);
var compThrow = ranThrow[roundPostRanNum];
var whatThrow = prompt("Rock, Papper or Scissors?", "rock");
var rpsGame = function () {
if (whatThrow === "rock" && compThrow === "rock") {
return "You tie!";
}
else if (whatThrow === "rock" && compThrow === "paper") {
return "You lose!";
}
else if (whatThrow === "rock" && compThrow === "scissor") {
return "You win!";
}
else {
return "Error";
}
};
rpsGame();
console.log("The computer threw" + " " + compThrow);
答案 0 :(得分:2)
函数内部没有忽略该值,它是调用函数的代码,忽略了函数返回的内容。
如果显示返回值,您将看到该函数使用值:
console.log(rpsGame());