Skip to content

solved lab #3506

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
54 changes: 51 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,55 @@
// Iteration 1: Names and Input
// Iteration 1: Names and Input ### Iteration 1: Names and Input
// Create two variables `hacker1` and `hacker2` and assign them the driver's and navigator's names.

const hacker1 = `Francisco`;
console.log(`The driver's name is ${hacker1}`);

// Iteration 2: Conditionals
const hacker2 = `Lucía`;
console.log(`The navigator's name is ${hacker2}`);

// Iteration 2: Conditionals ### Iteration 2: Conditionals

// Iteration 3: Loops
// No need to reassign hacker1 and hacker2, they are already declared above


// Paso 1: obtener las longitudes
const len1 = hacker1.length; // 9 caracteres
const len2 = hacker2.length; // 5 caracteres

// Paso 2: comparar longitudes
if (len1 > len2) {
console.log(`The driver has the longest name ${len1} caracteres.`);
} else if (len1 < len2) {
console.log(` It seems that the navigator has the longest name, it has ${len2} caracteres.`);
} else {
console.log(`Wow, you both have equally long names, ${len1} caracteres!`);
}

//*Iteration 3: Loops3.1 Print the characters of the driver's name, separated by space, and in capital letters, i.e., "J O H N".3.2 Print all the characters of the navigator's name in reverse order, i.e., "nhoJ".3.3 Depending on the lexicographic order of the strings, print:The driver's name goes first.Yo, the navigator goes first, definitely.What?! You both have the same name?*/

// 3.1 – Mostrar el nombre del driver en mayúsculas y separado por espacios
let nameWithSpaces = "";

for (let i = 0; i < hacker1.length; i++) {
nameWithSpaces += hacker1[i].toUpperCase() + " ";
}

console.log(nameWithSpaces);

// 3.2 – Mostrar el nombre del navigator al revés
let reversedName = "";

for (let i = hacker2.length - 1; i >= 0; i--) {
reversedName += hacker2[i];
}

console.log(reversedName);

// 3.3 – Comparar nombres en orden alfabético
if (hacker1 < hacker2) {
console.log("The driver's name goes first.");
} else if (hacker1 > hacker2) {
console.log("Yo, the navigator goes first, definitely.");
} else {
console.log("What?! You both have the same name?");
}