-
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 #3399 from samuelArandia/main
Reto #2 -JavaScript
- Loading branch information
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
Retos/Reto #2 - EL PARTIDO DE TENIS [Media]/javascript/samuelArandia.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 @@ | ||
function tennisGame (secuencia) { | ||
let game = ['Love', '15', '30', '40' ] | ||
let player1 = 0; | ||
let player2 = 0; | ||
let error = false; | ||
let finish = false; | ||
|
||
console.log('Comienza el partido'); | ||
for (let i = 0; i < secuencia.length; i++) { | ||
if (secuencia[i] === 'P1') { | ||
player1++; | ||
} else if (secuencia[i] === 'P2') { | ||
player2++; | ||
} else { | ||
error = true; | ||
break; | ||
} | ||
if (player1 >= 3 && player2 >=3) { | ||
if (player1 == player2) { | ||
console.log('Deuce'); | ||
}else if (player1 > player2) { | ||
console.log('Ventaja P1'); | ||
finish = true; | ||
} else if (player1 < player2) { | ||
console.log('Ventaja P2'); | ||
finish = true; | ||
} else { | ||
console.log('Error'); | ||
} | ||
} else if ( player1 <= 3 && player2 <= 3 && !finish) { | ||
console.log(`${game[player1]} - ${game[player2]}`); | ||
} else { | ||
finish = true; | ||
} | ||
|
||
if (finish) { | ||
if (player1 > player2) { | ||
console.log('Ha ganado el P1'); | ||
} else if (player1 < player2) { | ||
console.log('Ha ganado el P2'); | ||
} else { | ||
console.log('Error'); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
tennisGame(['P1', 'P1', 'P2', 'P2', 'P1', 'P2', 'P1', 'P1']); | ||
|
||
|
||
|
37 changes: 37 additions & 0 deletions
37
Retos/Reto #3 - EL GENERADOR DE CONTRASEÑAS [Media]/javascript/samuelArandia.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,37 @@ | ||
function passwordGenerator(length, upper, numbers, symbols) { | ||
|
||
let characters = "abcdefghijklmnopqrstuvwxyz"; | ||
let characterUpper = characters.toUpperCase(); | ||
let numbersCharacters = "0123456789"; | ||
let symbolsCharacters = "!#$%&/()=?¡¿"; | ||
let allCharacters = ""; | ||
let password = ""; | ||
|
||
for (let i = 0; i < length; i++) { | ||
if (upper) { | ||
allCharacters += characters + characterUpper; | ||
} else { | ||
allCharacters += characters; | ||
} | ||
if (numbers) { | ||
allCharacters += numbersCharacters; | ||
} | ||
if (symbols) { | ||
allCharacters += symbolsCharacters; | ||
} | ||
random = Math.floor(Math.random() * allCharacters.length); | ||
password += allCharacters.charAt(random); | ||
} | ||
console.log(password); | ||
return password; | ||
} | ||
passwordGenerator(8); | ||
passwordGenerator(8, true, true, true); | ||
passwordGenerator(10, false, true, true); | ||
passwordGenerator(13, true, true, true); | ||
passwordGenerator(16, true, false, true); | ||
passwordGenerator(20, true, true, true); | ||
passwordGenerator(8, false, false, false); | ||
passwordGenerator(10, true, true, false); | ||
passwordGenerator(14, false, false, true); | ||
|