Problem with my code during rock, paper, scissors project. functions

Im currently coding the rock paper scissors game and have gotten to this point where when i go to call “determineWinner”
i go to put 2 things inside like this "console.log(determineWinner(‘paper’, ‘paper’)) but the 2nd string causes the 2 end parentheses to become strings. only when i remove the 3rd curly bracket from the bottom of the code does it fix it but then that leaves my function declaration unclosed.

const determineWinner = (userChoice, computerChoice) => {
  if (userChoice === computerChoice) {
    return 'The game was 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!";
  }
 }
}; 
console.log(determineWinner('paper', 'paper'))

Hi welcome to the forums! :slight_smile:

Could you reformat the code in your post by deleting your code, pressing the Screen Shot 2020-12-28 at 3.54.18 PM button and pasting in-between the tick marks Screen Shot 2020-12-28 at 3.54.20 PM ? This will make the code more readable by users and someone can help you quicker/more accurately!

wow thank you!, thats much better

1 Like

I shouldn’t worry if the CC editor colours the closing parenthesis yellow-as long as the code works, there shouldn’t be any problems.

1 Like

ive tried running the code but it does not pull the user and computer choices. i get this error right here whenever i remove the 3rd curly bracket if it has anything that could help, i dont see where this error is so im not sure what its talking about

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

When I run it off platform, I get the expected result-“The game was a tie.”. Try copying your code, resetting the project, then pasting the code into it again.

2 Likes

ohhhh i see the problem, i thought that because i entered (‘paper’, ‘paper’) that it would change the value of userInput variable that was created early. so due to the fact that i left it blank it was making the code output the wrong way. which is weird because i could type ‘rock’ vs paper for userInput but make userChoice scissors and it out put win even tho userinput would have lost.

1 Like