From 03569677b09c3b8e0e8d91caa8cb10a855d7f85b Mon Sep 17 00:00:00 2001 From: dillandatanerd Date: Wed, 23 Jul 2025 16:53:13 +0200 Subject: [PATCH 1/3] iteration1 --- index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/index.js b/index.js index 6b0fec3ad..b78594351 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,20 @@ // Iteration 1: Names and Input +// 1.1 Create a variable hacker1 with the driver's name. +// 1.2 Print "The driver's name is XXXX". +// 1.3 Create a variable hacker2 with the navigator's name. +// 1.4 Print "The navigator's name is YYYY". + +const hacker1= "dillan" +const hacker2= "carlos" +const hacker3= "alejandro" + +console.log(`The driver's name is ${hacker1}`) +console.log(`The navigators are ${hacker2} and ${hacker3}`) // Iteration 2: Conditionals // Iteration 3: Loops + + From 0fd407ff98b704ab2f35341ba15cece8c338fe3a Mon Sep 17 00:00:00 2001 From: Alejandro Duque Date: Wed, 23 Jul 2025 16:20:03 +0100 Subject: [PATCH 2/3] Iteration 2 --- index.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b78594351..0f615c85f 100644 --- a/index.js +++ b/index.js @@ -13,8 +13,21 @@ console.log(`The navigators are ${hacker2} and ${hacker3}`) // Iteration 2: Conditionals - - +/*2.1. Depending on which name is longer, print: +- The driver has the longest name, it has XX characters. or +- It seems that the navigator has the longest name, it has XX characters. or +- Wow, you both have equally long names, XX characters!.*/ + +if (hacker1.length > hacker2.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 c003e758fdb112e0c22683a45d6450514c6f2118 Mon Sep 17 00:00:00 2001 From: Carlos Canet Date: Wed, 23 Jul 2025 17:49:37 +0200 Subject: [PATCH 3/3] All iterations done ;) --- .vscode/settings.json | 3 ++ index.js | 85 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..f673a71b7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5502 +} \ No newline at end of file diff --git a/index.js b/index.js index 0f615c85f..d6b126a4d 100644 --- a/index.js +++ b/index.js @@ -28,6 +28,89 @@ else if (hacker1.length < hacker2.length){ else { console.log(`Wow, you both have equally long names, ${hacker1.length} characters!.`) } -// Iteration 3: Loops +//! Iteration 3: Loops +// 3.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? +let str = ""; +for (let i = 0; i < hacker1.length; i++){ + str += hacker1[i].toUpperCase() + " "; +} + +console.log(str); + +str = ""; +for (let i = hacker1.length-1; i >= 0; i--) { + str += hacker1[i]; +} +console.log(str); + +if (hacker1 > hacker2){ + console.log(`Yo, the navigator goes first, definitely.`); +} else if (hacker1 < hacker2) { + console.log(`The driver's name goes first`); +} else { + console.log(`What?! You both have the same name?`); +} + +// BONUS +// Go to the lorem ipsum generator website and: + +// Generate 3 paragraphs. Store the text in a new string variable named longText. Generated 3 paragraphs, 222 words, 1544 bytes of Lorem Ipsum +// Make your program count the number of words in the string. +// Make your program count the number of times the Latin word et appears. + +const longText = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse bibendum accumsan nisi at ultricies. Proin aliquet ligula eget augue tempor sagittis. Sed semper elit a nibh auctor, sed aliquet nulla consequat. Pellentesque fermentum ante vitae dolor tincidunt tempor. Proin sem ligula, sollicitudin in massa a, bibendum vestibulum nisl. Quisque pretium felis nec nisl dapibus, eget pharetra lorem fermentum. Donec nec mollis nisl. Maecenas pellentesque malesuada lacus, sed pellentesque arcu. +Mauris aliquet consectetur fermentum. Vestibulum laoreet velit ut mollis faucibus. Suspendisse finibus sodales risus a tempor. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Aliquam vel malesuada metus, non convallis velit. Aliquam vel bibendum augue. Vestibulum posuere sit amet lectus non rhoncus. Fusce auctor lacus arcu, eget cursus nibh interdum et. Fusce finibus quam lectus, vel aliquet dui interdum eu. Aliquam in arcu condimentum, laoreet orci vitae, lobortis lectus. Nulla vestibulum convallis sapien a tempor. Cras vel enim semper, aliquet turpis sit amet, dignissim massa. Suspendisse ut egestas lacus. Etiam nunc erat, scelerisque vitae ullamcorper et, dapibus id tortor. +Integer vel sodales erat. Sed id molestie ipsum. Nam porta interdum feugiat. Ut ultricies lorem a odio laoreet, sed tincidunt turpis consequat. In eleifend turpis justo, et luctus ligula mattis in. In a enim ligula. Aliquam condimentum felis eget dolor pharetra fermentum. Aliquam ac scelerisque ligula, eu faucibus purus.`; + +let count = 0, countEt = 0; +for (let i = 0; i < longText.length; i++) { + if (longText[i] === " " || longText[i] === "\n") { + count++; + } + if (longText[i] === "e" && longText[i + 1] === "t") { + countEt++; + } +} +count++; + +console.log(count); +console.log(countEt); + +let countEt2 = 0, i = 0, lastIndex = -1; + +// lastIndex = longText.indexOf("et", 0); +// while (lastIndex >= 0) { +// countEt2++; +// i++; +// lastIndex = longText.indexOf("et", lastIndex+1); +// } + +do { + lastIndex = longText.indexOf("et", lastIndex+1); + i++; + if (lastIndex >= 0) { + countEt2++; + } +}while (lastIndex >= 0); +console.log(countEt2); + + + +const phraseToCheck = "A man, a plan, a caNal, PaNama!"; +let cleanPhrase = "", reversePhrase = ""; +for (let i = 0; i < phraseToCheck.length; i++) { + if ((phraseToCheck[i] >= "a" && phraseToCheck[i] <= "z") || (phraseToCheck[i] >= "A" && phraseToCheck[i] <= "Z")) { + cleanPhrase += phraseToCheck[i].toLowerCase(); + reversePhrase = phraseToCheck[i].toLowerCase() + reversePhrase; + } +} +if (cleanPhrase === reversePhrase) { + console.log("It is a PALINDROME!"); +} \ No newline at end of file