Doesn’t seem to be accepting the arrow function syntax - Help!

Hi all :slight_smile:

I am struggling with the rock paper scissors project, I think there might be an issue or bug with the code editor as it doesn’t seem to be accepting the arrow function syntax. I have tried to work around it and can by using parentheses around the single parameter which means I can make it past the first step, but then can’t seem to work around it for the second bit where you create a computer response as in the exercise it takes no parameters.

So here is the problem -

const getUserChoice = userInput => {};

When inputting the code like this, the code editor seems to think that the userInput is a predefined class or object (appears in red in code editor). I can resolve this by putting parentheses around the userInput as below:

const getUserChoice = (userInput) => {};

However, I was under the impression that parentheses are not required for single parameters and the hint in the exercise also writes the code as shown in the first example.

My next question would be, could this potentially be a browser issue? I am using safari v13.1
or an OS issue? - using macOs high sierra

Alternatively, am I doing something wrong?

I wanted to check here before raising a ticket if it is a bug, in case I am making some obvious newbie error.

Thanks in advance for any solutions or thoughts!

https://www.codecademy.com/paths/create-video-games-with-phaser/tracks/game-dev-learn-javascript-function-and-scope/modules/game-dev-learn-javascript-functions/projects/rock-paper-scissors-javascript

The syntax highlighting is only a hint at proper code structure/syntax. If your code still runs as expected then ignore the color difference. Indeed, a single parameter does not need parens (they are optional for that case only).

Thanks so much for the speedy reply, unfortunately it doesn’t run (again unless I am doing something wrong?) Using this code from the first part of the exercise:

const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if (userInput === ‘rock’|| ‘paper’|| ‘scissors’){
return userInput;
} else {
console.log(‘Error!’);
}
};
console.log(userInput(‘rock’));

It generates the following error:

/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:9
console.log(userInput(‘rock’));
^

ReferenceError: userInput is not defined
at Object. (/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:9:13)
at Module._compile (module.js:571:32)
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)
at bootstrap_node.js:542:3

Thanks again in advance for any further thoughts / comments / support :slight_smile:

That is not how to write a multiple condition expression.

if (a==='1' || a==='2' || a==='3')

We need complete expressions for each operand.

1 Like

and just like that I see what I did wrong, I didn’t console.log the function… So I will just ignore the colours! Thank you haha, just goes to show you can stare at something for hours and puzzle about it and still not see your own mistake until you make your mistake public! Thanks again :slight_smile:

thanks for also pointing this out! This no doubt would have been my next issue!

1 Like