//index.js
var playAction = process.argv[process.argv.length - 1];
console.log("玩家:"+playAction)
var radom = Math.random() * 3;
var action;
if (radom < 1) {
action = "剪刀";
} else if (radom > 2) {
action = "石头";
} else {
action = "布";
}
console.log("电脑:"+action)
if(playAction==action){
console.log("平局")
}else if(action == "剪刀"&&playAction=="石头"||action == "石头"&&playAction=="布"||action == "布"&&playAction=="剪刀"){
console.log("你赢了")
}else{
console.log("你输了")
}
输入终端代码:
node index "剪刀"
输出:
玩家:剪刀
电脑:石头
你输了
网友评论