Guest User

Untitled

a guest
Oct 20th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. const getUserChoice = userInput => {
  2. userInput = userInput.toLowerCase();
  3. if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') {
  4. return userInput;
  5. }
  6. else {
  7. console.log('error, not a valid choice. Please choose between "rock, paper, or scissors"');
  8. }
  9. };
  10.  
  11. const getComputerChoice = computerInput => {
  12. Math.floor(Math.random() * 3);
  13. if (computerInput === 0) {
  14. return 'rock';
  15. }
  16. if (computerInput === 1) {
  17. return 'paper';
  18. }
  19. if (computerInput === 2) {
  20. return 'scissors';
  21. }
  22. };
  23.  
  24. const determineWinner = (userChoice, computerChoice) => {
  25. if (userChoice === computerChoice) {
  26. return 'The game is a tie!';
  27. }
  28. if (userChoice === 'scissors') {
  29. if (computerChoice === 'paper') {
  30. return 'You have won!.';
  31. }
  32. else {
  33. return 'The computer has won.';
  34. }
  35. }
  36. if (userChoice === 'paper') {
  37. if (computerChoice === 'rock') {
  38. return 'You have won!.';
  39. }
  40. else {
  41. return 'The computer has won.';
  42. }
  43. }
  44. if (userChoice === 'rock') {
  45. if (computerChoice === 'scissors') {
  46. return 'You have won!.';
  47. }
  48. else {
  49. return 'The computer has won.';
  50. }
  51. }
  52. if (userChoice === 'bomb') {
  53. if (computerChoice === 'rock') {
  54. return 'Cheater....';
  55. }
  56. }
  57. if (userChoice === 'bomb') {
  58. if (computerChoice === 'scissors') {
  59. return 'Cheater....';
  60. }
  61. }
  62. if (userChoice === 'bomb') {
  63. if (computerChoice === 'paper') {
  64. return 'Cheater....';
  65. }
  66. }
  67. };
  68.  
  69. const playGame = () => {
  70. const userChoice = prompt();
  71. const computerChoice = prompt();
  72. console.log('The user chose: ' + userChoice);
  73. console.log('The computer chose: ' + computerChoice);
  74.  
  75. console.log(determineWinner(userChoice, computerChoice));
  76. };
  77.  
  78. playGame();
Add Comment
Please, Sign In to add comment