|
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
1 | 5 | // Iteration 1: Names and Input
|
2 | 6 |
|
3 | 7 |
|
| 8 | +const hacker1 = 'John'; |
| 9 | +console.log(`The driver is ${hacker1}`); |
| 10 | + |
| 11 | +const hacker2 = 'Navigator'; |
| 12 | +console.log(`The navigator´s name is ${hacker2}`); |
| 13 | + |
| 14 | + |
4 | 15 | // Iteration 2: Conditionals
|
5 | 16 |
|
| 17 | +if (hacker1.length > hacker2.length) { |
| 18 | + console.log(`The driver has the longest name, it has ${hacker1.length} characters`); |
| 19 | + } else if (hacker1.length < hacker2.length) { |
| 20 | + console.log(`It seems that the navigator has the longest name, it has ${hacker2.length} characters`); |
| 21 | + } else { |
| 22 | + console.log(`"Wow, you both have equally long names, ${hacker1.length} characters!"`) |
| 23 | + } |
| 24 | + |
6 | 25 |
|
7 | 26 | // Iteration 3: Loops
|
| 27 | + |
| 28 | + |
| 29 | +let nombreEnMayusculas = "" // <- variable helper |
| 30 | + |
| 31 | +for (let i = 0; i < hacker1.length; i++) { |
| 32 | + nombreEnMayusculas = nombreEnMayusculas + hacker1[i].toUpperCase() + " " |
| 33 | +} |
| 34 | + |
| 35 | +console.log(nombreEnMayusculas) |
| 36 | + |
| 37 | +let nombreInvertido = "" // <- variable helper |
| 38 | + |
| 39 | +for (let i = hacker1.length - 1; i >= 0; i--) { |
| 40 | + nombreInvertido = nombreInvertido + hacker1[i] |
| 41 | +} |
| 42 | + |
| 43 | +console.log(nombreInvertido) |
| 44 | + |
| 45 | + |
| 46 | +/////////////////////////////////////////////////////////// |
| 47 | + |
| 48 | +const names = [hacker1, hacker2] |
| 49 | + |
| 50 | +for (i=0; i < names.length; i++) { |
| 51 | + if (names[0].length > names[1].length) { |
| 52 | + console.log("The driver's name goest first."); |
| 53 | + } else if (names[0].length < names[1].length) { |
| 54 | + console.log("Yo, the navigator goes first, definitely."); |
| 55 | + } else { |
| 56 | + console.log("What?! You both have the same name?"); |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | + |
| 61 | + |
0 commit comments