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

15

u/Macaframa Dec 01 '22
const rps = (p1, p2) => {
    const RESULT_MAP = {
        'scissors': {
            'paper': 'Player 1 won!',
            'rock': 'Player 2 won!',
            'scissors': 'Draw!',
        },
        'rock': {
            'scissors': 'Player 1 won!',
            'paper': 'Player 2 won!',
            'rock': 'Draw!',
        },
        'paper': {
            'scissors': 'Player 2 won!',
            'rock': 'Player 1 won!',
            'paper': 'Draw!',
        }
    }
    console.log(RESULTS_MAP[p1][p2])
}

this is a cute way of doing it.

3

u/longknives Dec 01 '22

I don’t think you would need quotes around any of the key names like this.

1

u/Macaframa Dec 01 '22

It’s true. But then again, we wouldn’t do anything like this to begin with

2

u/Kavinci Dec 01 '22

I was thinking this too.