-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathindex.js
46 lines (33 loc) · 1.46 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Iteration 1: Names and Input
let hackerOne = "Ana";
console.log(`The driver's name is ${hackerOne}.`);
let hackerTwo = "Jose";
console.log(`The driver's name is ${hackerTwo}.`);
// Iteration 2: Conditionals
if (hackerOne.length > hackerTwo.length) {
console.log(`The driver has the longest name, it has ${hackerOne.length} characters.`);
}
else if (hackerOne.length < hackerTwo.length) {
console.log(`It seems that the navigator has the longest name, it has ${hackerTwo.length} characters.`);
}
else {
console.log(`Wow, you both have equally long names, ${hackerOne.length} characters!.`);
}
// Iteration 3: Loops
/*split(""): Divide la cadena en un array de caracteres individuales.
join(" "): Une esos caracteres de nuevo, pero esta vez con un espacio entre ellos.*/
let driverSplit = hackerOne.toUpperCase().split("").join(" ");
console.log(driverSplit);
/*cadenas de texto no tiene metodo reverse, por lo que hay que pasar cadena de texto a array con un *split*, luego *reverse* y volver a pasar a cadena de texto con *join**
aprovecho para pasarlo a minusculas con toLowerCase */
let navigatorReverse = hackerTwo.toLowerCase().split("").reverse().join("");
console.log(navigatorReverse);
if (hackerOne.localeCompare(hackerTwo) > 0) {
console.log(`The driver's name goes first.`);
}
else if (hackerOne.localeCompare(hackerTwo) < 0) {
console.log(`Yo, the navigator goes first, definitely.`);
}
else {
console.log(`What?! You both have the same name?`);
}