-
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 pull request #6604 from IkalNaran/main
Reto #2 - JavaScript
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
Retos/Reto #2 - EL PARTIDO DE TENIS [Media]/javascript/IkalNaran.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,45 @@ | ||
const gameTennis = (secuencia) => { | ||
const pointGame = [15, 30, 40, 41, 42, 43, 44]; | ||
|
||
let pointP1 = 0; | ||
let pointP2 = 0; | ||
let gameWinP1 = ["Love"]; | ||
let gameWinP2 = ["Love"]; | ||
let win1 = 1; | ||
let win2 = 1; | ||
|
||
for (element of secuencia) { | ||
(element == 'P1') ? gameWinP1.push(pointGame[pointP1++]) : (element == 'P2') ? gameWinP2.push(pointGame[pointP2++]) : ""; | ||
let player1 = gameWinP1[pointP1]; | ||
let player2 = gameWinP2[pointP2]; | ||
let playerMayor = player1 >= 40 && player2 >= 40; | ||
|
||
try { | ||
if ((player1 == player2) && playerMayor) { | ||
console.log('Douce'); | ||
win1 = 1; | ||
win2 = 1; | ||
} else if (player1 > 40 && player2 <= 30 || player1 <= 30 && player2 >= 40) { | ||
console.log(`Ha ganado ${element}`); | ||
break; | ||
} else if (win1 >= 2 || win2 >= 2) { | ||
console.log(`Ha ganado ${element}`); | ||
break; | ||
} else if (pointP1 > pointP2 && playerMayor) { | ||
console.log(`Ventaja ${element}`); | ||
win1++; | ||
} else if ((player1 < player2) && playerMayor) { | ||
console.log(`Ventaja ${element}`); | ||
win2++; | ||
} else console.log(`${player1} - ${player2}`); | ||
|
||
} catch (error) { | ||
console.log(error); | ||
} | ||
} | ||
|
||
} | ||
|
||
let secuencia1 = ['P2', 'P1', 'P1', 'P2', 'P1', 'P2', 'P1', 'P2', 'P2', 'P2', 'P2']; | ||
let secuencia = ['P1', 'P1', 'P2', 'P2', 'P1', 'P2', 'P1', 'P1']; | ||
gameTennis(secuencia); |