Arrow function Javascript-Why my code show error? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Arrow function Javascript-Why my code show error?

const getUserChoice = ***(userInput)*** => { userInput = userInput.toLowerCase(); if (userInput==='rock' || userInput ==='paper'|| userInput==='scissors') { return userInput ; } else { return 'Error'; } } It working fine const getUserChoice = **userInput** => { userInput = userInput.toLowerCase(); if (userInput==='rock' || userInput ==='paper'|| userInput==='scissors') { return userInput ; } else { return 'Error'; } } It shows error. as far as I know, if a function has only one parameter it is not necessary to use parenthesis but in this code snippet, it seems like parenthesis is mandatory.can anyone explain why?

15th Sep 2020, 10:10 AM
SHAH MD JALAL UDDIN
SHAH MD JALAL UDDIN - avatar
2 Answers
+ 2
I just removed the asterisks around the function parameter name and the code just works. What error message did you get BTW?
15th Sep 2020, 2:12 PM
Ipang
0
the 1st part is working but the 2nd part didn't.it shows syntex error although the only difference is a parenthesis in the parameter.
15th Sep 2020, 2:48 PM
SHAH MD JALAL UDDIN
SHAH MD JALAL UDDIN - avatar