From 10d48ed891b6c7c99195690da0863a3d30127ccd Mon Sep 17 00:00:00 2001 From: GuaSiMoTO Date: Fri, 20 Mar 2026 18:10:55 +0100 Subject: [PATCH 1/3] LAB terminado con bonus --- index.js | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/index.js b/index.js index 6b0fec3ad..dd520929e 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,133 @@ // Iteration 1: Names and Input +let hacker1 = "Gandalf el blanco"; //driver´s name + +console.log(`The driver´s name is ${hacker1}`); + +let hacker2 = "Antonio"; //navigator´s name + +console.log(`The navigator´s name is ${hacker2}`); // Iteration 2: Conditionals +if (hacker1.length > hacker2.length) { + console.log(`The driver has the longest ${hacker1}, it has ${hacker1.length} characters`); +} else if (hacker1.length < hacker2.length) { + console.log(`The driver has the longest ${hacker2}, it has ${hacker2.length} characters`); +} else { + console.log(`Wow, you both have equally long names, ${hacker1.length} characters!`); +} + +/* +if (hacker1.length > hacker2.length) console.log(`The driver has the longest ${hacker1}, it has ${hacker1.length} characters`); +else if (hacker1.length < hacker2.length) console.log(`The driver has the longest ${hacker2}, it has ${hacker2.length} characters`); +else console.log(`Wow, you both have equally long names, ${hacker1.length} characters!`); +*/ + + + +/* +Terciario: (iteration 2.1 solo las dos primera condiciones) + +hacker1.length > hacker2.length ? console.log(`The driver has the longest ${hacker1}, it has ${hacker1.length} characters`) : console.log(`The driver has the longest ${hacker2}, it has ${hacker2.length} characters`); +*/ // Iteration 3: Loops + +//3.1 +let hacker1SeparedLetters=""; + +for (let i=0; i < hacker1.length; i++) { + hacker1SeparedLetters += hacker1[i].toUpperCase() + " "; +} + +console.log(hacker1SeparedLetters); + +let hacker1Reversed =""; + +//3.2 + +for (let i=hacker1.length - 1; i >= 0; i--) { + hacker1Reversed += hacker1[i]; +} + +console.log(hacker1Reversed); + +//3.3 +//Palíndromo + +if (hacker1.toLowerCase() < hacker2.toLowerCase()) { + console.log(`The driver's name goes first`); +} else if (hacker1.toLowerCase() > hacker2.toLowerCase()) { + console.log(`Yo, the navigator goes first, definitely.`); +} else { + console.log(`What?! You both have the same name?`); +} + + +// BONUS 1 + +let longText = "Lorem ipsum dolor sit amet consectetur adipisicing elit. Nobis delectus repellat alias architecto! Voluptates, et ab tenetur quae in hic atque excepturi, perferendis, fugiat rem ut unde amet sunt cum. Lorem ipsum dolor sit amet consectetur adipisicing elit. Nesciunt ipsam nemo error, doloribus obcaecati eligendi suscipit excepturi! Excepturi minus amet, quia ullam nostrum similique, quasi corporis ratione, labore blanditiis repellendus. Lorem ipsum dolor sit amet consectetur adipisicing elit. Omnis, iure nisi doloremque aliquid officiis aspernatur enim dicta, alias repellat id quae quos. Fugiat, quae. Eum temporibus ex ea animi id?" + +// count words +let countLetters = 1; +for (let i=0; i < longText.length; i++) { + if (longText[i] === " ") countLetters ++; +} + +console.log(`the numbers of word in longText is ${countLetters}`); + + +// count "et" + +let countEt = 0; + +for (let i=0; i < longText.length - 1; i++) { + if ((longText[i].toLowerCase() + longText[i + 1].toLowerCase()) === "et") countEt++; +} + +console.log(`the numbers of "et" in longText is ${countEt}`); + +// BONUS 2 + +let phraseToCheck = "No 'x' in Nixon"; +let cleanPhrase= ""; + +for (let i= 0; i < phraseToCheck.length; i++) { // recorro la frase y la dejo limpia para comparar + + let char = phraseToCheck[i].toLowerCase(); // cada caracter en lower case + + if (char !== " " && char !== "," && char !=="!" && char !== "?" && char !== "'") { + cleanPhrase += char; + } +} + +let isPalindromo = true; + +for (let i = 0; i < cleanPhrase.length / 2; i++) { + if (cleanPhrase[i] !== cleanPhrase[(cleanPhrase.length -1) - i]) { + isPalindrome = false; + break + } +} + +if (isPalindrome) { + console.log(`${phraseToCheck} is PALINDROME`); +} else { + console.log(`${phraseToCheck} is NOT PALINDROME`); +} + +// Otra manera es comparar también la frase limpia al reverso + +let cleanPhraseReversed = ""; + +for (let i= phraseToCheck.length - 1 ; i >= 0 ; i--) { // recorro la frase y la dejo limpia para comparar + + let char = phraseToCheck[i].toLowerCase(); // cada caracter en lower case + + if (char !== " " && char !== "," && char !=="!" && char !== "?" && char !== "'") { + cleanPhraseReversed += char; + } +} + +cleanPhrase === cleanPhraseReversed ? console.log("IS PALINDROME") : console.log("IS NOT PALINDROME"); \ No newline at end of file From adfa4ce1cdc91a54e7f8cdb4655664eb90340065 Mon Sep 17 00:00:00 2001 From: GuaSiMoTO Date: Fri, 20 Mar 2026 18:21:15 +0100 Subject: [PATCH 2/3] iteration 3.1 mejorado --- index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index dd520929e..f32cdaaa6 100644 --- a/index.js +++ b/index.js @@ -38,7 +38,12 @@ hacker1.length > hacker2.length ? console.log(`The driver has the longest ${hack let hacker1SeparedLetters=""; for (let i=0; i < hacker1.length; i++) { - hacker1SeparedLetters += hacker1[i].toUpperCase() + " "; + + if (i !== hacker1.length - 1) { // para no añadir un espacio al final + hacker1SeparedLetters += hacker1[i].toUpperCase() + " "; + }else { + hacker1SeparedLetters += hacker1[i].toUpperCase(); + } } console.log(hacker1SeparedLetters); From 52819130a2f08990bbb897682fa0b203a635b6c1 Mon Sep 17 00:00:00 2001 From: GuaSiMoTO Date: Fri, 20 Mar 2026 18:23:56 +0100 Subject: [PATCH 3/3] =?UTF-8?q?peque=C3=B1a=20correci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index f32cdaaa6..7bd04cb66 100644 --- a/index.js +++ b/index.js @@ -107,7 +107,7 @@ for (let i= 0; i < phraseToCheck.length; i++) { // recorro la frase y la dejo l } } -let isPalindromo = true; +let isPalindrome = true; for (let i = 0; i < cleanPhrase.length / 2; i++) { if (cleanPhrase[i] !== cleanPhrase[(cleanPhrase.length -1) - i]) {