Hi guys uhm I think your learning interface might be bugging [Rock Paper Scissors JS Project]

Not to criticize or anything it’s just that I have been, for what it seems, hours in front of my screen trying to solve this problem with no success. I think I may be actually turning yellow.

So the problem is the following:

/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:64
});
^
SyntaxError: Unexpected token )
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)

And my code is the following:

//Human's turn to play.
const getUserChoice = (userInput = userInput.toLowerCase()) =>{
  if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors'){
  return userInput;
}else{
  console.log('Invalid Input');
}
};
console.log(getUserChoice('paper'));


//Computer's turn to play. 
function getComputerChoice(){
  randomNumber = Math.floor(Math.random()*3);
  switch(randomNumber){
  case 0:
  return 'rock';
  case 1:
  return 'scissors';
  case 2:
  return 'paper';
}
}
console.log(getComputerChoice());

//Determining the winner.
function determineWinner(userChoice, computerChoice){
  if(userChoice === computerChoice){
  return 'Its a tie!';
  }
  if(userChoice === 'rock'){
    if(computerChoice === 'paper'){
      return 'Computer Wins!';
    }else{
      return 'Human Wins!';
    }
  }
  if(userChoice === 'paper'){
    if(computerChoice === 'scissors'){
      return 'Computer Wins!';
    }else{
      return 'Human Wins!';
    }
  }
  if(userChoice === 'scissors'){
    if(computerChoice === 'rock'){
    return 'Computer Wins!';
  }else{
    return 'Human Wins!';
  }
}
console.log(determineWinner('rock','paper'));

//Creating game program.
function playGame(){
  const userChoice = getUserChoice('rock');
  const computerChoice = getComputerChoice();
  console.log(userChoice);
  console.log(computerChoice);
  console.log(determineWinner(userChoice, computerChoice));
};
playGame();

For some random reason, the console is displaying an error on what it seems to me as line 64? Not completely sure it actually represents the command line but I’ll let my intuition win this time. Besides my code ends on line 62.

It’s not the first time this happens on this project, as I have previously read multiple topics on the forum complaining about the same error. However, it keeps happening.

If someone knows anything about how to fix this issue, I’m a taker!

:grin: :grin:

Hey Patrick,

Hope you’re well.

I think you’re missing a closing curly bracket on your determineWinner function?

function determineWinner(userChoice, computerChoice) {
  if (userChoice === computerChoice) {
    return 'Its a tie!';
  }
  if (userChoice === 'rock') {
    if (computerChoice === 'paper') {
      return 'Computer Wins!';
    } else {
      return 'Human Wins!';
    }
  }
  if (userChoice === 'paper') {
    if (computerChoice === 'scissors') {
      return 'Computer Wins!';
    } else {
      return 'Human Wins!';
    }
  }
  if (userChoice === 'scissors') {
    if (computerChoice === 'rock') {
      return 'Computer Wins!';
    } else {
      return 'Human Wins!';
    }
  }

2 Likes

Hey ghost!

Really nice to hear from you again, you lifesaver.

Well you are absolutely right, I was missing the @$!@ curly bracket at the end of determineWinner. :joy: :rofl:

After spending so much time staring at my screen and finding nothing, and now after taking a break it feels so evident… A practice I’ll keep in mind for future coding hours!

Nothing else to say besides thanks again @ghostlovescore

Peace :v:

3 Likes

I suggest working with an actual editor that’ll help you debug syntax much easier. I like using sublime but atom is awesome too (I’ve never tried the others but there are good ones). You have to build the js compiler in sublime but it’s pretty simple.

It will save you a lot of needless frustration!

1 Like

Personally, I have never really tried out any code editors. I’ll give those a look.

Thanks for your advice @toastedpitabread!

1 Like