Last active
July 9, 2020 17:20
-
-
Save CodeNextAdmin/3d0882f2cf21d408742ec3d793e8d14d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const READLINE = require("readline-sync"); | |
const options = ["rock", "paper", "scissors"]; | |
console.log(`Let's play Rock Paper Scissors!`); | |
while(true){ | |
let userInput = READLINE.question(`Do you want to play rock, paper, or scissors? `).toLowerCase(); | |
let randomSelection = Math.floor(Math.random()*3); | |
let computerSelection = options[randomSelection]; | |
console.log(`You played: ${userInput} and the computer played: ${computerSelection}`); | |
if(userInput === computerSelection){ | |
console.log("It's a tie!"); | |
} | |
else if((userInput === "rock" && computerSelection === "paper") || | |
(userInput === "paper" && computerSelection === "scissors") || | |
(userInput === "scissors" && computerSelection === "rock")){ | |
console.log("You Lose!"); | |
} | |
else{ | |
console.log("You Win!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment