Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getUserChoice(userInput) {
- userInput = userInput.toLowerCase();
- if (userInput === 'bear' || userInput === 'human' || userInput === 'gun') {
- return userInput;
- } else {
- return 'Please enter valid option';
- }
- }
- function getComputerChoice() {
- var randomNumber = Math.floor(Math.random() * 3);
- if (randomNumber === 0) {
- return 'bear'
- } else if (randomNumber === 1) {
- return 'human';
- } else {
- return 'gun';
- }
- }
- function determineWinner(userChoice, computerChoice) {
- if (userChoice === computerChoice) {
- return 'you\'re neither a loser nor a winner';
- }
- if (userChoice === 'human') {
- if (computerChoice === 'bear') {
- return 'you suck';
- } else {
- return 'you\'re sub par I guess ¯\_(ツ)_/¯';
- }
- }
- if (userChoice === 'bear') {
- if (computerChoice === 'gun') {
- return 'you suck';
- } else {
- return 'you\'re sub par I guess ¯\_(ツ)_/¯';
- }
- }
- if (userChoice === 'gun') {
- if (computerChoice === 'human') {
- return 'you suck';
- } else {
- return 'you\'re sub par I guess ¯\_(ツ)_/¯';
- }
- }
- }
- function playGame() {
- var promptUserChoice = prompt('Please chose bear, human, or gun');
- var userChoice = getUserChoice(promptUserChoice);
- var computerChoice = getComputerChoice();
- console.log(userChoice);
- console.log(computerChoice);
- console.log(determineWinner(userChoice, computerChoice));
- }
- playGame();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement