-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'mouredev:main' into main
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
Retos/Reto #6 - PIEDRA, PAPEL, TIJERA, LAGARTO, SPOCK [Media]/javascript/dPenedo.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |