Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const getUserChoice = (userInput) => {
- userInput = userInput.toLowerCase();
- if(userInput === 'rock' || userInput === 'paper' || userInput === 'scissors' || userInput === 'bomb'){
- return userInput;
- } else {
- console.log('You didn\'t do anything');
- }
- };
- function getComputerChoice(){
- const randomNumber = Math.floor(Math.random() * 3);
- switch(randomNumber) {
- case 0:
- return 'rock';
- break;
- case 1:
- return 'paper';
- break;
- case 2:
- return 'scissors';
- break;
- }
- }
- function determineWinner(userChoice, computerChoice){
- if(userChoice === computerChoice){
- return 'tie';
- }
- if(userChoice === 'rock'){
- if (computerChoice === 'paper'){
- return 'Computer won';
- } else {
- return 'User won';
- }
- }
- if(userChoice === 'paper') {
- if (computerChoice === 'scissors'){
- return 'User won';
- } else if (computerChoice === 'rock'){
- return 'Computer won';
- }
- }
- if(userChoice === 'scissors') {
- if (computerChoice === 'rock'){
- return 'User won';
- } else if (computerChoice === 'paper'){
- return 'Computer won';
- }
- }
- if(userChoice === 'bomb'){
- return 'U DESTROYED BRO';
- }
- }
- const playGame = () => {
- const userChoice = getUserChoice('bomb');
- const computerChoice = getComputerChoice();
- console.log('You threw: ' + userChoice);
- console.log('The computer threw:' + computerChoice);
- console.log(determineWinner(userChoice, computerChoice));
- };
- playGame();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement