Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. const getUserChoice =userInput => {
  2. let x = userInput;
  3. userInput = x.toLowerCase();
  4. if (userInput === 'rock'){
  5. return userInput; }
  6. else if(userInput === 'scissors'){
  7. return userInput;}
  8. if (userInput === 'paper'){
  9. return userInput;}
  10. if (true){ return console.log ('user input wrong value')}
  11. };
  12. getUserChoice('scissors');
  13. const getComputerChoice = () => {
  14. let val = Math.floor(Math.random()*3)
  15. if (val === 0){
  16. return 'rock';}
  17. else if (val === 1){
  18. return 'scissors';}
  19. if (val===2){
  20. return 'paper'
  21. } }
  22. const determineWinner = (userChoice,computerChoice) =>{
  23. if (userChoice === computerChoice)
  24. {
  25. return 'Game was tied'
  26. }
  27. else if (userChoice === 'rock')
  28. {
  29. if (computerChoice === 'paper'){
  30. return console.log('Computer won')
  31. } else { return console.log('user won')}
  32. }
  33. else if (userChoice === 'paper')
  34. {
  35. if (computerChoice === 'scissor')
  36. {
  37. return console.log('Computer won')
  38. }
  39. else { return console.log('user won')}
  40. if (userChoice === 'scissor')
  41. {
  42. if (computerChoice === 'rock')
  43. {
  44. return console.log('Computer won')
  45. }
  46. else {return console.log('user won')}
  47. }
  48. }
  49. }
  50. //let compu = getComputerChoice();
  51. //let humano = getUserChoice();
  52. //console.log(determineWinner(humano,compu));
  53. //console.log('compu: '+ getComputerChoice());
  54. const playGame = function (userChoice,computerChoice){
  55. userChoice=getUserChoice ('');
  56. console.log(userChoice)
  57. computerChoice = getComputerChoice();
  58. console.log(computerChoice);
  59. }
  60. let x='';
  61. let y= getComputerChoice();
  62. console.log(playGame(x,y));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement