Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const getUserChoice =userInput => {
- let x = userInput;
- userInput = x.toLowerCase();
- if (userInput === 'rock'){
- return userInput; }
- else if(userInput === 'scissors'){
- return userInput;}
- if (userInput === 'paper'){
- return userInput;}
- if (true){ return console.log ('user input wrong value')}
- };
- getUserChoice('scissors');
- const getComputerChoice = () => {
- let val = Math.floor(Math.random()*3)
- if (val === 0){
- return 'rock';}
- else if (val === 1){
- return 'scissors';}
- if (val===2){
- return 'paper'
- } }
- const determineWinner = (userChoice,computerChoice) =>{
- if (userChoice === computerChoice)
- {
- return 'Game was tied'
- }
- else if (userChoice === 'rock')
- {
- if (computerChoice === 'paper'){
- return console.log('Computer won')
- } else { return console.log('user won')}
- }
- else if (userChoice === 'paper')
- {
- if (computerChoice === 'scissor')
- {
- return console.log('Computer won')
- }
- else { return console.log('user won')}
- if (userChoice === 'scissor')
- {
- if (computerChoice === 'rock')
- {
- return console.log('Computer won')
- }
- else {return console.log('user won')}
- }
- }
- }
- //let compu = getComputerChoice();
- //let humano = getUserChoice();
- //console.log(determineWinner(humano,compu));
- //console.log('compu: '+ getComputerChoice());
- const playGame = function (userChoice,computerChoice){
- userChoice=getUserChoice ('');
- console.log(userChoice)
- computerChoice = getComputerChoice();
- console.log(computerChoice);
- }
- let x='';
- let y= getComputerChoice();
- console.log(playGame(x,y));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement