daily pastebin goal
46%
SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getUserChoice(userInput) {
  2.   userInput = userInput.toLowerCase();
  3.   if (userInput === 'bear' || userInput === 'human' || userInput === 'gun') {
  4.     return userInput;
  5.   } else {
  6.     return 'Please enter valid option';
  7.   }
  8. }
  9.  
  10. function getComputerChoice() {
  11.   var randomNumber = Math.floor(Math.random() * 3);
  12.   if (randomNumber === 0) {
  13.     return 'bear'
  14.   } else if (randomNumber === 1) {
  15.     return 'human';
  16.   } else {
  17.     return 'gun';
  18.   }
  19.  
  20. }
  21.  
  22. function determineWinner(userChoice, computerChoice) {
  23.   if (userChoice === computerChoice) {
  24.     return 'you\'re neither a loser nor a winner';
  25.   }
  26.  
  27.   if (userChoice === 'human') {
  28.     if (computerChoice === 'bear') {
  29.       return 'you suck';
  30.     } else {
  31.       return 'you\'re sub par I guess ¯\_(ツ)_/¯';
  32.     }
  33.   }
  34.   if (userChoice === 'bear') {
  35.     if (computerChoice === 'gun') {
  36.       return 'you suck';
  37.     } else {
  38.       return 'you\'re sub par I guess ¯\_(ツ)_/¯';
  39.     }
  40.   }
  41.  
  42.   if (userChoice === 'gun') {
  43.     if (computerChoice === 'human') {
  44.       return 'you suck';
  45.     } else {
  46.       return 'you\'re sub par I guess ¯\_(ツ)_/¯';
  47.     }
  48.   }
  49. }
  50.  
  51. function playGame() {
  52.   var promptUserChoice = prompt('Please chose bear, human, or gun');
  53.   var userChoice = getUserChoice(promptUserChoice);
  54.   var computerChoice = getComputerChoice();
  55.   console.log(userChoice);
  56.   console.log(computerChoice);
  57.   console.log(determineWinner(userChoice, computerChoice));
  58. }
  59. playGame();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top