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:
https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-javascript-syntax-part-i/modules/fecp-learn-javascript-syntax-functions/projects/rock-paper-scissors-javascript
Screenshot:
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: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Missing_initializer_in_const
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: https://softwareengineering.stackexchange.com/questions/364086/why-use-const-foo-instead-of-function-foo. 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!