HELP! "Missing initializer in const declaration"

Hey everyone,

I don’t understand why this error occurs.

The block of code that this error points to:

const determineWinner(user, computer) => {
  if (user === computer){
    return 'tie!';
  if (user === 'rock'){
    if (computer === 'scissors'){
      return 'User wins!';
    } else {
      return 'Computer Wins!';
  } else if (user === 'scissors'){
    if (computer === 'rock'){
      return 'computer wins';
    } else {return 'user wins';}
  } else { // user is paper
    if (computer === 'rock') {
      return 'user wins';
    } else {
      return 'computer wins';

The link to the project which I’m currently stuck on:


Thank you!

The format of your declaration is off.

Try something like
const test = (example) => { return 0; }

Also note, const declarations always need to be set to a value, so you will always see const equals something.

Also note you can always check documentation on this matter:

But @locstylz brings up a good point that you may not necessarily want a const function here (maybe just a garden variety arrow or old-fashioned function). I think it’s always useful to be mindful of the strengths and weaknesses of what one declares. Here’s a link to a conversation about that: But it’s not an easy topic at all. Just note there’s no hoisting with const functions (among other things).

1 Like

I’ll have to try that myself. Thank you toastedpitabread!

Here’s a link to the project for rockPaperScissors in JavaScript.

Hope this helps!

Here’s a look at the same code with the syntax a little more organized.

Happy coding!