Rock paper scissors

hi guys so i can’t figure this out this is my code and I’m probably being a noob right now so the console is telling me this error:

/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:45
const playGame = () => {
^^^^^
SyntaxError: Unexpected token const
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)

this is my code:

  userInput = userInput.toLowerCase();
  if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors'){
    return userInput;
  }else{
    console.log('Booy! We be playin\' rock paper scissors! I know you ain\'t stupid!')
  }
}
function getComputerChoice(){
const cChoice =Math.floor(Math.random () *3);
  switch(cChoice){
    case 0:
      return 'rock';
    case 1:
      return 'paper';
    case 2:
      return 'scissors';
   }
}
function determineWinner(userChoice,computerChoice){
  if(userChoice === computerChoice){
    return 'sorry man, it\'s a tie.'
  }
  if (userChoice === 'rock'){
   if(computerChoice === 'paper'){
     return 'You picked rock and computer picked paper. Maybye you can learn from your mistakes man!'
    }else{
     return 'Kudos to you! If you haven\'t guessed yet, ya won.'
    }
    if (userChoice === 'paper'){
      if (computerChoice === 'scissors') {
       return '3...2...1... YA LOST!!!' 
      }else{
       return 'You won. I wish you didn\'t.'
      }
      if (userChoice==='scissors'){
          return 'you lost because im all seeing.Oh wait! I didnt mean to say that!';
        }else{
          return 'ERROR: YOU WON. IMA1!37754¢57  @$55%^564545467%^&%^$#';
        }
      }
    }
  }
}
const playGame = () => {
  const userChoice = getUserChoice('scissors');
  const computerChoice = getComputerChoice();
  console.log(`you threw a ${userChoice}.`);
  console.log(`they threw a ${computerChoice}.`);
  console.log(determineWinner(userChoice,computerChoice))
}
playGame();

```also dont mind the computer responses

The file you’re showing appears to be incomplete, it will not produce an error message like that.

It does show inconsistent indentation though, so maybe you tricked yourself into mismatching braces. If you always insert them in pairs and indent to match then you shouldn’t have this happen. Most programming editors also help out one way or another in balancing braces and indenting. There are also tools for reformatting code, which would also aid in keeping things sane/detecting issues. Having lots of nesting doesn’t make things easier.

that fixed the error but now every time i have scissors as the user choice the console says ‘undefined’ if there is not a tie.
here is the code:

 if (userChoice==='scissors'){
      if (computerChoice === 'rock')
      { return 'you lost because im all seeing.Oh wait! I didnt mean to say that!';
        }else{
          return 'ERROR: YOU WON. IMA1!37754¢57  @$55%^564545467%^&%^$#';
        }
     }    

Hey @iamcool123456789!

if (userChoice === 'paper'){
      if (computerChoice === 'scissors') {
       return '3...2...1... YA LOST!!!' 
      }else{
       return 'You won. I wish you didn\'t.'
      }
      if (userChoice==='scissors'){
          return 'you lost because im all seeing.Oh wait! I didnt mean to say that!';
        }else{
          return 'ERROR: YOU WON. IMA1!37754¢57  @$55%^564545467%^&%^$#';
        }

I think you are missing a closing curly bracket at the end of the if (userChoice === 'paper') function.

You’d have to ensure that each possible (reasonable) input leads to a return statement instead of just reaching the end of the function and returning nothing in particular.

A suggestion is to make your function smaller by breaking out rock/paper/scissors into their own functions, that way it’ll be easier to see that all those nested if’s are correct because you could just have:

if player is scissors {
    return scissors(otherplayer)
}
if player is paper {
    return paper(otherplayer)
}
if player is rock {
    return rock(otherplayer)
}

each of those would have much less to deal with.

I wouldn’t do it this way, but it’s definitely one way to to bring your large amount of nesting under control while still keeping the logic exactly the same.

…what I mean is, if this code was given to me, I would change it quite a lot and it wouldn’t really resemble the original.
Also, it doesn’t necessarily need to be broken out into functions, it IS still manageable, but you’re demonstrating some trouble with that. Which is fine, you’ll figure that out, but making it simpler is very much worth exploring as well because it’s not a crutch it’s a good strategy.

Regarding what I WOULD do, (but really not that relevant because the whole point is to work on your code)
that’s something like putting the input and output versions in some data structure:

[[[rock, paper], response1],
 [[rock, scissors], response2],
 [[paper, rock], response3],
 [[paper, scissors], response4],
 [[scissors, rock], response5],
 [[scissors, paper], resoponse6]
]

And then write some code that looks for a match and returns the corresponding response