From 1a7dd6ad78ad115aa8077cd4635e57476b977d17 Mon Sep 17 00:00:00 2001 From: Alejandra Rodriguez Date: Wed, 23 Jul 2025 16:41:37 +0200 Subject: [PATCH 1/4] Iteration 1 done --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 6b0fec3ad..015231095 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,8 @@ // Iteration 1: Names and Input - +let hacker1 = "Alejandra" +console.log(`The driver's name is ${hacker1}`) +let hacker2 = "Mael" +console.log(`The navigator's name is ${hacker2}`) // Iteration 2: Conditionals From 6daf8aaff31429d615b8f97c133b3782a72c1f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Odina=20Eug=C3=A8ne?= Date: Wed, 23 Jul 2025 16:55:37 +0200 Subject: [PATCH 2/4] Conditionals iteration - finished --- index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 015231095..fc315452a 100644 --- a/index.js +++ b/index.js @@ -6,5 +6,12 @@ console.log(`The navigator's name is ${hacker2}`) // Iteration 2: Conditionals - +if (hacker2.length < hacker1.length) +{ + console.log(`The driver has the longest name, it has ${hacker1.length} characters.`) +} else if ( hacker1.length < hacker2.length) { + console.log(`It seems that the navigator has the longest name, it has ${hacker2.length} characters.`) +} else { + console.log(`Wow, you both have equally long names, ${hacker1.length} characters!`) +} // Iteration 3: Loops From d87eb5897a9813d24e76d82b57e0c1ecb0a44863 Mon Sep 17 00:00:00 2001 From: Alejandra Rodriguez Date: Wed, 23 Jul 2025 18:24:31 +0200 Subject: [PATCH 3/4] Iteration 3 (loops) finished --- index.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/index.js b/index.js index fc315452a..551cb8607 100644 --- a/index.js +++ b/index.js @@ -15,3 +15,54 @@ if (hacker2.length < hacker1.length) console.log(`Wow, you both have equally long names, ${hacker1.length} characters!`) } // Iteration 3: Loops +let hacker1UpperCase = "" +for(let i = 0; i < hacker1.length; i++){ + hacker1UpperCase += hacker1[i].toUpperCase() + " "; +} +console.log(hacker1UpperCase) + +let hacker2Reversed = ""; +// for(let i = 0 ; i < hacker2.length; i++){ +// hacker2Reversed += hacker2[hacker2.length - 1 - i] +// } +// console.log(hacker2Reversed) + +for(let i = (hacker2.length-1); i >= 0; i--){ + hacker2Reversed += hacker2[i] +} +console.log(hacker2Reversed) + +// Excercise #3 +// hacker2 = "Alejandro" +// hacker2 = "Ale" + +let hackerHigherLexOrder = "" +let symbol ="" +let iter = 0 + +let hackerWithShortestName = hacker1.length < hacker2.length ? hacker1:hacker2 +let selectedLength = hackerWithShortestName.length +console.log(`Length of the shortest name is ${selectedLength} (${hackerWithShortestName})`) + +for(let i = 0; i < selectedLength ; i++ ){ + iter = i + 1; + if(hacker1[i] < hacker2[i]){ + hackerHigherLexOrder = hacker1; + // console.log(`${iter}) ${hacker1[i]} (${hacker1[i].charCodeAt(0)}) is before ${hacker2[i]} (${hacker2[i].charCodeAt(0)})`) + break; + }else if(hacker1[i] > hacker2[i]){ + hackerHigherLexOrder = hacker2; + // console.log(`${iter}) ${hacker1[i]} (${hacker1[i].charCodeAt(0)}) is after ${hacker2[i]} (${hacker2[i].charCodeAt(0)})`) + }else{ + hackerHigherLexOrder = hackerWithShortestName + // console.log(`${iter}) ${hacker1[i]} (${hacker1[i].charCodeAt(0)}) = ${hacker2[i]} (${hacker2[i].charCodeAt(0)})`) + } +} + +if(hackerHigherLexOrder === hacker1){ + console.log(`The driver's name goes first.(${hackerHigherLexOrder})`) +}else if(hackerHigherLexOrder === hacker2){ + console.log(`Yo, the navigator goes first, definitely.(${hackerHigherLexOrder})`) +}else{ + console.log("What?! You both have the same name?") +} \ No newline at end of file From ca81f8b697d6c2f03dff3c28054222c52f2d4c80 Mon Sep 17 00:00:00 2001 From: Alejandra Rodriguez Date: Wed, 23 Jul 2025 23:29:42 +0200 Subject: [PATCH 4/4] Bonus 1 finished --- index.js | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 551cb8607..3236e1951 100644 --- a/index.js +++ b/index.js @@ -65,4 +65,60 @@ if(hackerHigherLexOrder === hacker1){ console.log(`Yo, the navigator goes first, definitely.(${hackerHigherLexOrder})`) }else{ console.log("What?! You both have the same name?") -} \ No newline at end of file +} + +// Bonus 1 +let longText = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi congue convallis nisl, vitae laoreet mauris. Fusce tempus, ipsum nec molestie egestas, magna nisl euismod justo, nec rutrum justo nibh id augue. In id leo sit amet turpis tincidunt commodo ut vitae ante. Cras vulputate elit et molestie auctor. Etiam rhoncus lobortis quam eget elementum. Nullam in enim leo. Ut porttitor sapien vitae rutrum accumsan. + +Mauris ullamcorper lacus orci. Suspendisse vehicula blandit enim, non pulvinar enim aliquam id. Nulla vel nisl hendrerit, sagittis leo quis, egestas nunc. Integer fermentum venenatis mattis. Maecenas fermentum neque at nunc vestibulum, at fringilla metus cursus. Vivamus convallis lorem nec ante venenatis porttitor. Donec euismod leo ut leo tempor, eu tristique enim pellentesque. Nullam quis nibh est. Nunc non varius nunc. Vestibulum condimentum vitae purus ut iaculis. + +Vestibulum ornare ullamcorper felis, ut egestas velit. Mauris feugiat interdum eros sit amet cursus. Donec in libero non velit faucibus euismod. Ut eu velit vel lectus facilisis dictum nec id dolor. Phasellus varius auctor augue porta mollis. Integer eget interdum nisl. Vestibulum id mollis diam. Ut in sapien lacus. Curabitur aliquam eleifend aliquet. Aenean sodales risus elit, vel convallis eros aliquet a. Fusce sed malesuada velit. Sed id elit nec lectus tincidunt elementum. Suspendisse tempor, mauris sit amet maximus efficitur, ipsum urna commodo nunc, nec faucibus nulla dolor sollicitudin turpis. Maecenas aliquam dapibus nunc, nec rhoncus elit. Pellentesque libero libero, aliquam sed est sit amet, efficitur fringilla urna.` +// longText = "Hola Mundo" + +let wordCounter = 0 +let word = "" +let etCounter = 0 +for(let i = 0; i < longText.length; i++){ + if (longText[i] !== " " && longText[i] !== "\n"){ + word += longText[i] + }else{ + if(word.length > 0){ + wordCounter++; + } + // console.log(`${wordCounter}) ${word}`) + if(word === "et"){ + etCounter++; + } + word = ""; + } +} +// If word is not empty, but neither " ", nor /n was not found after it, then it is the last word, and it has not been counted yet. So add it to the count. +if (word.length > 0) { + wordCounter++; +} +console.log(`There are ${wordCounter} words in the paragraphs`) +console.log(`There are ${etCounter} "et" words in the paragraphs`) +// console.log(`There are ${lineBreakCounter} line breaks`) + +// let startIndex = 0 +// let lastIndexWord = 0 +// for(let i = 0; i < longText.length; i++){ +// if (longText[i] == " " || longText[i] == "\n"){ +// lastIndexWord = i; +// break; +// } +// } +// palabra = longText.slice(startIndex, lastIndexWord) +// console.log(`palabra: ${palabra}`) + +// let wordsArray =[] +// for(let i = 0; i < longText.length; i++){ +// if (longText[i] !== " " && longText[i] !== "\n"){ +// // console.log(`i:${i}) char:${longText[i]}`) +// word += longText[i] +// }else{ +// wordsArray.push(word) +// word = ""; +// } +// } +// console.log(wordsArray) \ No newline at end of file