// //Start game

console.log('Welcome to Rock Paper Scissors!');

//Gather user input

let playerChoice = prompt('Choose either Rock, Paper, or Scissors:');

//Create computer's choice

let computerChoice = Math.random(); if (computerChoice < 0.34) { computerChoice = 'rock'; } else if(computerChoice <= 0.67) { computerChoice = 'paper'; } else { computerChoice = 'scissors'; }

//Display choices

console.log('Computer: ' + computerChoice); console.log('Player: ' + playerChoice);

//Compare choices

let compare = function(choice1, choice2){ if(choice1 === choice2){ return 'It's a tie!'; } else if(choice1 === 'rock'){ if(choice2 === 'scissors'){ return 'rock wins'; } else{ return 'paper wins'; } } else if(choice1 === 'paper'){ if(choice2 === 'rock'){ return 'paper wins'; } else{ return 'scissors wins'; } } else if(choice1 === 'scissors'){ if(choice2 === 'rock'){ return 'rock wins'; } else{ return 'scissors wins'; } } };

//Display results

console.log(compare(playerChoice, computerChoice));

Play Rock Paper Scissors Online - Simple Game

原文地址: https://www.cveoy.top/t/topic/lmqN 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录