node.js学习记录
1,安装nodejs开发环境
简单实现的石头剪刀布
console.log(process) //这个是node自带的
var playAction = process.argv[process.argv.length - 1]
console.log(playAction)
var random = Math.random() * 3
if (random < 1) {
var computerAction = 'rock'
} else if (random > 2) {
var computerAction = 'sicssor'
} else {
var computerAction = 'paper'
}
if (playAction === computerAction) {
console.log('平局')
} else if (
(computerAction === 'rock' && playAction === 'paper') ||
(computerAction === 'sicssor' && playAction === 'rock') ||
(computerAction === 'paper' && playAction === 'sicssor')
) {
console.log('你赢了')
} else {
console.log('你输了')
}
process.exit() //杀进程
版权声明:本文由Web学习之路发布,如需转载请注明出处。