Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.92 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.   <head>
  4.     <meta charset="utf-8"/>
  5.     <title>Console Based Rock-Paper-Scissors</title>
  6.     <style>
  7.     </style>
  8.   </head>
  9.   <body>
  10.   </body>
  11.   <script>
  12.     //Player Moves
  13.     let playerHand = prompt('Pick your destiny');
  14.     playerHand = normalize(playerHand);
  15.     play(playerHand);
  16.  
  17.     function normalize(playerHand) {
  18.         let selectionLower = playerHand;
  19.         let selectionUpper = playerHand;
  20.         selectionLower = selectionLower.slice(1, playerHand.length)
  21.         selectionLower = selectionLower.toLowerCase();
  22.         selectionUpper = selectionUpper.charAt(0);
  23.         selectionUpper = selectionUpper.toUpperCase();
  24.     return selectionUpper + selectionLower;
  25.     }
  26.  
  27.     function play(playerHand) {
  28.         if (playerHand === 'Rock') {
  29.             let playerSelection = 'Rock';
  30.             console.log('You threw ' + playerSelection + '!');
  31.         } else if (playerHand === 'Paper'){
  32.             let playerSelection = 'Paper';
  33.             console.log('You threw ' + playerSelection + '!');
  34.         } else if (playerHand === 'Scissors'){
  35.             let playerSelection = 'Scissors';
  36.             console.log('You threw ' + playerSelection + '!');
  37.         } else {
  38.             alert('Please enter your move, Rock, Paper, or Scissors')
  39.             let playerHand = prompt('Pick your destiny');
  40.             playerHand = normalize(playerHand);
  41.             play(playerHand);
  42.         }
  43.     }
  44.  
  45.     //Computer Moves
  46.     let hands = ['Rock', 'Paper', 'Scissors'];
  47.     computerPlay(hands);
  48.  
  49.     function computerPlay(array) {
  50.       let hand = array[random(array.length, 0)];
  51.       return hand;
  52.     }
  53.  
  54.     function random(upper, lower) {
  55.         let num = Math.floor(Math.random() * (upper - lower) + lower);
  56.         return num
  57.     }
  58.  
  59.     const computerSelection = computerPlay()
  60.     console.log(playRound(playerSelection, computerSelection))
  61.  
  62.  
  63.   </script>
  64. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement