From e7a099d93a30cc6afebd2d76d5dfe6a0f46a615f Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 22 Mar 2024 17:22:29 -0300 Subject: [PATCH] Reto 6 resuelto con javascript --- .../javascript/dPenedo.js | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Retos/Reto #6 - PIEDRA, PAPEL, TIJERA, LAGARTO, SPOCK [Media]/javascript/dPenedo.js diff --git a/Retos/Reto #6 - PIEDRA, PAPEL, TIJERA, LAGARTO, SPOCK [Media]/javascript/dPenedo.js b/Retos/Reto #6 - PIEDRA, PAPEL, TIJERA, LAGARTO, SPOCK [Media]/javascript/dPenedo.js new file mode 100644 index 0000000000..8f0540db7e --- /dev/null +++ b/Retos/Reto #6 - PIEDRA, PAPEL, TIJERA, LAGARTO, SPOCK [Media]/javascript/dPenedo.js @@ -0,0 +1,51 @@ +// Crea un programa que calcule quien gana mΓ‘s partidas al piedra, +// papel, tijera, lagarto, spock. +// - El resultado puede ser: "Player 1", "Player 2", "Tie" (empate) +// - La funciΓ³n recibe un listado que contiene pares, representando cada jugada. +// - El par puede contener combinaciones de "πŸ—Ώ" (piedra), "πŸ“„" (papel), +// "βœ‚οΈ" (tijera), "🦎" (lagarto) o "πŸ––" (spock). +// - Ejemplo. Entrada: [("πŸ—Ώ","βœ‚οΈ"), ("βœ‚οΈ","πŸ—Ώ"), ("πŸ“„","βœ‚οΈ")]. Resultado: "Player 2". +// - Debes buscar informaciΓ³n sobre cΓ³mo se juega con estas 5 posibilidades. + +const winsAgainst = { + 'πŸ—Ώ': ['βœ‚οΈ', '🦎'], + 'πŸ“„': ['πŸ—Ώ', 'πŸ––'], + 'βœ‚οΈ': ['πŸ“„', '🦎'], + '🦎': ['πŸ“„', 'πŸ––'], + 'πŸ––': ['βœ‚οΈ', 'πŸ—Ώ'], +}; + +function playGame(gameArray) { + let player1Score = 0; + let player2Score = 0; + for (let i = 0; i < gameArray.length; i++) { + const player1Emoji = gameArray[i][0]; + const player2Emoji = gameArray[i][1]; + console.log(`Game ${i + 1}:`); + console.log(`Player1: ${player1Emoji} | Player2: ${player2Emoji}`); + if (winsAgainst[player1Emoji].includes(player2Emoji)) { + console.log('Point for player 1'); + player1Score++; + } else { + console.log('Point for player 2'); + player2Score++; + } + console.log('---------------------------'); + } + console.log('==========================='); + if (player1Score > player2Score) { + console.log('πŸ† Player 1 wins the game!'); + } else if (player2Score > player1Score) { + console.log('πŸ† Player 2 wins the game!'); + } else { + console.log("It's a tie!"); + } +} + +const gameInput = [ + ['πŸ—Ώ', 'βœ‚οΈ'], + ['βœ‚οΈ', 'πŸ—Ώ'], + ['πŸ“„', 'βœ‚οΈ'], +]; + +playGame(gameInput);