Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reto #2 -JavaScript #3399

Merged
merged 4 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);