node 剪刀石头布

var playerAction = process.argv[process.argv.length - 1];
console.log(playerAction);
var random = Math.random() * 3;
if (random < 1) {
  var computerAction = "rock";
} else if (random > 2) {
  var computerAction = "scissor";
} else {
  var computerAction = "paper";
}

if (playerAction === computerAction) {
  console.log("平局");
} else if (
  (playerAction === "rock" && computerAction === "scissor") ||
  (playerAction === "scissor" && computerAction === "paper") ||
  (playerAction === "paper" && computerAction === "rock")
) {
  console.log("你赢了");
} else {
  console.log("你输了");
}

 

posted @ 2020-10-31 16:15  夏天的西瓜君  阅读(123)  评论(0编辑  收藏  举报