-
-
Save codecademydev/946b6355fef6a6f475d013fcb6e2c022 to your computer and use it in GitHub Desktop.
Codecademy export
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
var userInput = '' ; | |
uesrInput = userInput.toLowerCase(); | |
const function getUserChoice = userInput =>{ | |
if(userInput === 'rock' || userInput ==='paper' || userInput==='scissors') | |
return userInput; | |
else{ | |
console.log('Invalild input'); | |
} | |
} | |
function getComputerChoice(){ | |
var randomNumber = Math.floor (Math.random() *3) ; | |
switch(randomNumber){ | |
case 0: | |
return 'rock'; | |
case 1: | |
return 'paper'; | |
case 2: | |
return 'scissors'; | |
default: | |
return 'Invalid choice'; | |
} | |
} | |
function determineWinner(userChoice, computerChoice){ | |
if(userChoice === computerChoice) | |
return ' The game is a tie!'; | |
if(userChoice === 'rock'){ | |
if(computerChoice === 'paper'){ | |
return 'The computer won!'; | |
} | |
else | |
return 'You Won!'; | |
} | |
if(userChoice === 'paper'){ | |
if(computerChoice === 'scissors') | |
return 'The computer won!'; | |
else | |
return 'You Won!'; | |
} | |
if(userChoice === 'scissors'){ | |
if(computerChoice === 'rock'){ | |
return 'The computer won!'; | |
} | |
else | |
return 'You Won!'; | |
} | |
} | |
const function playGame(){ | |
const userChoice = getUserChoice('scissors'; | |
const computerChoice = getComputerChoice (); | |
console.log('Your Choice: ' + userChoice); | |
console.log(' Computer Choice: ' + computerChoice); | |
console.log(determineWinner(userChoice, computerChoice)); | |
} | |
playGame(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment