Astrum96

Untitled

Dec 27th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <title>Tic Tac Toe</title>
  5.     </head>
  6.     <body>
  7.         <script>
  8.             const computerPlay = () => {
  9.                 let randomNumber = Math.floor(Math.random()*3);
  10.                 if (randomNumber == 1) {
  11.                     return "paper";
  12.                 } else if (randomNumber == 2) {
  13.                     return "rock";
  14.                 } else {
  15.                     return "scissor";
  16.                 }
  17.             };
  18.  
  19.             const playRound = (player, computer) => {
  20.                 const playerInput = player.toLowerCase();
  21.                 if (playerInput == "rock" && computer == "paper" || playerInput == "paper" && computer == "scissor" || playerInput == "scissor" && computer == "rock") {
  22.                     return (`You lose! ${computer} beats ${playerInput}`);
  23.                 } else if (playerInput == "paper" && computer == "rock" || playerInput == "scissor" && computer == "paper" || playerInput == "rock" && computer == "scissor") {
  24.                     return (`you win! ${playerInput} beats ${computer}`);
  25.                 } else {
  26.                     return (`Its a tie! ${playerInput} equals ${computer}`);
  27.                 }
  28.             };
  29.  
  30.             const playerSelection = () => {
  31.                 let selection = prompt("rock, paper or scissor? choose one!");
  32.                 return selection;
  33.             };
  34.  
  35.             const game = () => {
  36.                 console.log(playRound(playerSelection(), computerPlay()));
  37.                 console.log(playRound(playerSelection(), computerPlay()));
  38.                 console.log(playRound(playerSelection(), computerPlay()));
  39.                 console.log(playRound(playerSelection(), computerPlay()));
  40.                 console.log(playRound(playerSelection(), computerPlay()));
  41.             };
  42.  
  43.             game();
  44.         </script>
  45.     </body>
  46. </html>
Add Comment
Please, Sign In to add comment