石头剪刀逻辑问题



刚刚开始使用Odin项目学习Javascript。建造石头剪刀和我正在努力建立我的逻辑";oN我的oWn";但有点卡住了。

我有电脑和玩家的输入。但是,一个返回字符串,而另一个是数字。解决方案

此外,我认为我的游戏逻辑有缺陷。

const rps = ["ROCK", "PAPER", "SCISSORS"];
let computerPlay =  Math.floor(Math.random() * rps.length);
console.log(rps[computerPlay]);
let playerSelection = window.prompt("ROCK, PAPER, or SCISSORS?")
console.log(playerSelection, computerPlay);
/* Need to change both to strings? */

/* Game Logic*/
if (playerSelection === "ROCK") {
if (computerPlay === "ROCK")
return "TIE: Both selected ROCK";
else if (computerPlay === "PAPER")
return "You Lose! PAPER beats ROCK";
else (computerPlay === "SCISSORS")
return "You Won! ROCK beats SCISSORS";
} 
else if (playerSelection === "PAPER") {
if (computerPlay === "PAPER")
return "TIE: Both selected PAPER";
else if (computerPlay === "ROCK")
return "You Won! PAPER beats ROCK";
else (computerPlay === "SCISSORS")
return "You Lose! SCISSORS beats PAPER";
} else if (playerSelection === "SCISSORS") {
if (computerPlay === "SCISSORS")
return "TIE: Both selected SCISSORS";
else if (computerPlay === "PAPER")
return "You Won! SCISSORS beats PAPER";
else (computerPlay === "ROCK")
return "You Lose! ROCK beats SCISSORS";}```

在基本的Recon之后,您在computerPlay中有您的随机数,并且您试图将其与用户的输入进行比较,这是完全错误的。您需要将rps[computerPlay]与用户响应进行比较。

相关内容

  • 没有找到相关文章

最新更新