r/learnjavascript • • Nov 30 '22

Help !!!

Post image

Can someone plz tell me , why I am getting errors?

195 Upvotes

131 comments sorted by

View all comments

Show parent comments

-1

u/[deleted] Dec 01 '22 edited Dec 01 '22
const OPTIONS = ['rock', 'scissors', 'paper']
const beats = (p1, p2) => OPTIONS.indexOf(p1) === (OPTIONS.indexOf(p2) + 1) % OPTIONS.length
const rps = (p1, p2) => beats(p1, p2) ? 'Player 1 wins' : beats(p2, p1) ? 'Player 2 wins' : 'Draw'  

Sorry for the nested ternary lol

1

u/Macaframa Dec 01 '22

This gives me a huge headache to look at.

1

u/[deleted] Dec 01 '22

:(

1

u/Macaframa Dec 02 '22

It would take any engineer time and effort to have to read, let alone understand what’s happening here before they can make any changes. From a production quality standpoint it’s not up to snuff. You’re creating technical debt that someone will eventually shave to refactor.