-
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 #5236 from sandybierhoff/main
Reto #2 - Javascript
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
Retos/Reto #2 - EL PARTIDO DE TENIS [Media]/javascript/sandybierhoff.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,42 @@ | ||
const P1 = "P1"; | ||
const P2 = "P2"; | ||
|
||
function playTenis(...secuence) { | ||
let printScore = function() { | ||
let getValue = function(value) { | ||
const values = { 0: 'Love', 1: '15', 2: '30', 3: '40' }; | ||
if(value in values) return values[value]; | ||
} | ||
|
||
if (score[0] == score[1] && score[0] >= 3) | ||
console.log('Deuce'); | ||
else if (score[0] > score[1] && (score[0] - score[1]) == 1 && score[0] > 3) | ||
console.log('Ventaja P1'); | ||
else if (score[1] > score[0] && (score[1] - score[0]) == 1 && score[1] > 3) | ||
console.log('Ventaja P2'); | ||
else if (score[1] - score[0] > 1 && score[1] > 4) | ||
console.log('Ha ganado el P2'); | ||
else if (score[0] - score[1] > 1 && score[0] > 4) | ||
console.log('Ha ganado el P1'); | ||
else { | ||
console.log(`${getValue(score[0])} - ${getValue(score[1])}`); | ||
} | ||
} | ||
|
||
let score = [0, 0]; | ||
|
||
for (let index = 0; index < secuence.length; index++) { | ||
const element = secuence[index]; | ||
if(element !== P1 && element !== P2) continue; | ||
|
||
if (element.length!=2) continue; | ||
const player = parseInt(element[1]); | ||
if (player!=1 && player!=2) continue; | ||
|
||
score[player-1] += 1; | ||
|
||
printScore(); | ||
} | ||
} | ||
|
||
playTenis('P1', 'P1', 'P2', 'P2', 'P1', 'P2', 'P1', 'P1'); |