Skip to content

Commit

Permalink
Merge pull request #3399 from samuelArandia/main
Browse files Browse the repository at this point in the history
Reto #2 -JavaScript
  • Loading branch information
Roswell468 authored May 12, 2023
2 parents 5a23ab1 + 4198d34 commit 8fbd18b
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
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']);



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);

0 comments on commit 8fbd18b

Please sign in to comment.