MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/z8z4jh/help/iygoit3/?context=3
r/learnjavascript • u/Lelouch_5 • Nov 30 '22
Can someone plz tell me , why I am getting errors?
131 comments sorted by
View all comments
1
// Map of all possible game outcomes const outcomes = new Map( [ [ 'rock-rock', 'Draw!'], [ 'paper-paper', 'Draw!'], [ 'scissors-scissors', 'Draw!'], [ 'rock-scissors', 'Player 1 won!'], [ 'paper-rock', 'Player 1 won!'], [ 'scissors-paper', 'Player 1 won!'], [ 'rock-paper', 'Player 2 won!'], [ 'paper-scissors', 'Player 2 won!'], [ 'scissors-rock','Player 2 won!'] ] ) /** * Rock Paper Scissors game outcome * @param p1 {string} Player 1 selection * @param p2 {string} Player 2 selection */ const rps = (p1, p2) => { // create key for game outcome const game = [p1,p2].join( '-'); // determine outcome by looking it up console.log( outcomes.get(game) ?? 'Unknown game'); } rps( 'scissors', 'paper'); rps( 'paper', 'scissors'); rps( 'fred', 'paper');
1
u/girl-InTheSwing Dec 01 '22 edited Dec 01 '22