From 498fbbc067a9a6798fb442c8a82a6201227e5872 Mon Sep 17 00:00:00 2001 From: Noah Date: Sun, 15 Mar 2026 16:45:06 +0100 Subject: [PATCH] done --- README.md | 1 + index.js | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) diff --git a/README.md b/README.md index 71ce09db5..924059741 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,7 @@ We hope you enjoy it! :blue_heart: 3.1 Print the characters of the driver's name, separated by space, and [in capital letters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase), 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](https://en.wikipedia.org/wiki/Lexicographical_order) of the strings, print:
diff --git a/index.js b/index.js index 6b0fec3ad..e4c2d926a 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,124 @@ // Iteration 1: Names and Input +// let hacker1 = "Max"; + +// console.log(`The driver's name is ${hacker1}`); + + +// let hacker2 = "Daniel"; + +// console.log(`Then navigator's name is ${hacker2}`); // Iteration 2: Conditionals +// 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!. + +let driver = "Maximum"; + +let navigator = "Daniela"; + +if (driver.length > navigator.length){ + console.log(`The driver has the longest name, it has ${driver.length} characters.`); +} + +else if (driver.length < navigator.length){ + console.log(`It seems that the navigator has the longest name, it has ${navigator.length} characters`) +} +else { + console.log(`Wow, you both have equally long names, ${driver} ${driver.length} ${navigator} ${navigator.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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase), 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](https://en.wikipedia.org/wiki/Lexicographical_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 space = "" + +for (let i = 0; i < driver.length; i++){ + space += driver[i].toUpperCase() + " "; +} + +console.log(space); + + +let space2 = "" + +for (let i = 0; i < driver.length; i++){ + space2 = space2 + driver[i].toUpperCase() + " "; +} + +console.log(space2); + + +let result = driver.toUpperCase().split("").join(" "); + +console.log(result); + + +result = ""; + +for(let i = 0; i < navigator.length; i++){ + result = navigator.split('').reverse().join(''); +} +console.log(result) + + + + +let reverseName = navigator.split('').reverse().join(''); + +console.log(reverseName); + + + + +let reverse = ""; + + +for(let i = navigator.length -1; i >= 0; i--){ + reverse += navigator[i] +} + +console.log(reverse); + + + + +let reverseNameV2 = ""; + +for(let i = navigator.length -1; 0 >= i; i--){ + reverseName2 += navigator[i]; +} + +console.log(reverseNameV2); + + + +let reverseName2 = ""; + + +for(let i = navigator.length -1; i >=0; i--){ + reverseName2 += navigator[i]; +} + +console.log(reverseName2); + + +if (driver < navigator) { + console.log("The driver's name goes first."); +} else if (driver > navigator) { + console.log("Yo, the navigator goes first, definitely."); +} else { + console.log("What?! You both have the same name?"); +} \ No newline at end of file